Search the Community

Showing results for tags 'powershell'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • General
    • Announcements and Site News
    • Chat
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office


  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office


  • Forum
  • AutoIt


  • Community Calendar

Found 34 results

  1. Not sure if this is possible or if someone has already tackled this. Is it possible to embed PowerShell into a GUI? Autoit is great for quick function but sometime I need to run a command thru PowerShell. It be great to have PowerShell console embedded into the gui.
  2. After much searching I finally found a method to get eMails from an Exchange eMail account inbox. I was hoping for AutoIT or vbscript but I couldn't find any that would read the inbox messages without using Outlook. I needed this because I'm testing a web-form that generates an eMail sent to a shared mailbox "not what my current outlook is configured for". so, I needed to connect to a different account, then get the inbox messages, and see if the auto-generated eMail message body contains what I submitted in the form. I found a PowerShell script that was close and modified it to do just what I want, but I'd still like it to run in AutoIT but I'm not sure how to use the Microsoft.Exchange.WebServices.dll Anybody have some ideas? #To Launch! # C:\Windows\System32> powershell -ExecutionPolicy ByPass #This launches PowerShell and allows execution of .ps1 files # PS C:\Windows\System32> . "C:\Temp\eMail\getInbox.ps1" #The period . in front of the .ps1 file forces PS to display results on-screen # Where is the EWS .DLL file that you are using # Get the installer from # We only need 2 dll's from the install and they can be stored anywhere: "Microsoft.Exchange.WebServices.Auth.dll" & "Microsoft.Exchange.WebServices.dll" $EWSdll = "C:\Temp\eMail\Microsoft.Exchange.WebServices.dll" # Where do you want the output text file to be saved $Output = "C:\Temp\eMails.txt" # replace with your email address $email = "" # only need to populate these if you're impersonating... $username = "myemail" $password = "Sup3rS3cre+" $domain = "" # load the assembly : point to the dll in the location you have the .dll file [void] [Reflection.Assembly]::LoadFile($EWSdll) # set ref to exchange, first references 2007, 2nd is 2010 (default) #$s = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1) $s = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService # use first option if you want to impersonate, otherwise, grab your own credentials with the 3rd one. not sure what the 2nd one is for $s.Credentials = New-Object Net.NetworkCredential($username, $password, $domain) ##$s.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials #$s.UseDefaultCredentials = $true # discover the url from your email address $s.AutodiscoverUrl($email) # get a handle to the inbox $inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($s,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox) #create a property set (to let us access the body & other details not available from the FindItems call) $psPropertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties) $psPropertySet.RequestedBodyType = [Microsoft.Exchange.WebServices.Data.BodyType]::Text; # If you have a set number of items you want to get, use this and insert the # in the () # $items = $inbox.FindItems(5) # If you want to retrieve all items (Server limit is usually at 1000) then use this line # Details on the max returned by server: $items = $inbox.FindItems($inbox.TotalCount) # Put some counts at the top of the output Write-host "Total Inbox count: $($inbox.TotalCount)" Write-host "Unread count: $($inbox.UnreadCount)" #These two lines, write the output to the specified text file Add-Content $Output "Total Inbox count: $($inbox.TotalCount)" Add-Content $Output "Unread count: $($inbox.UnreadCount)" foreach ($item in $items.Items) { # load the property set to allow us to get to the body $item.load($psPropertySet) # Get the Body text as-is $bod = $item.Body.Text #if you only want a short summary of the Body, then comment the above line and un-comment these 4 lines # $bod = $item.Body.Text -replace '\s+', ' ' # $bodCutOff = (100,$bod.Length | Measure-Object -Minimum).Minimum # $bod = $bod.Substring(0,$bodCutOff) # $bod = "$bod..." # output the results - first of all the From, Subject, References and Message ID write-host "====================================================================" Write-host "From: $($item.From.Name)" Write-host "Subject: $($item.Subject)" Write-host "Body: $($bod)" write-host "====================================================================" "" # Output the results to the specified Text file Add-Content $Output "" Add-Content $Output "====================================================================" Add-Content $Output "From: $($item.From.Name)" Add-Content $Output "Subject: $($item.Subject)" Add-Content $Output "Body:",$($bod) Add-Content $Output "====================================================================" Add-Content $Output "" } #see these URLs for more info # EWS Stuff # folder members: # exporting headers: # read emails with EWS: Thanks, Mike
  3. Hi all, I need to read a log file into an array, but the log file is encoded as $FO_UTF16_BE_NOBOM (2048) = Use Unicode UTF16 Big Endian (without BOM) per FileGetEncoding (it returns 2048). I have searched how to convert these log files to UTF-8 and finally found a Powershell command. Since then I have been racking my brain trying to get the function to work. The command itself works from a Powerscript prompt: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command Get-Content C:\Logs\Myplayer_10-10-17-02-31.log | Set-Content -Encoding utf8 C:\Logs\Myplayer1.log This is my sandbox; #include <array.au3> #include <File.au3> Local $aArrayLogFile Local $sLogDir = "C:\Logs\" Local $sLogFile = "Myplayer_10-10-17-02-31.log" Local $sConvertedLog = "ConvertedLog.log" Local $sLogDirFile = $sLogDir&$sLogFile RunWait("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command Get-Content "&$sLogDirFile&" | Set-Content -Encoding utf8 "&$sConvertedLog,$sLogDir) _FileReadToArray($sLogDirFile, $aArrayLogFile) _ArrayDisplay($aArrayLogFile) Also tried RunWait("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command Get-Content "&$sLogDirFile&" | Set-Content -Encoding utf8 "&$sConvertedLog,$sLogDir) and ShellExecuteWait("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"," -Command Get-Content "&$sLogDirFile&" | Set-Content -Encoding utf8 "&$sConvertedLog,$sLogDir) Tried without -Command and a bunch of other parameters that were sprinkled throughout the internet from people trying to get this to work. Thanks Jibs
  4. I am maintaining all the reusable code in a separate file as library.au3. In that file I have referenced some dependent files using fileinstall, so that they will be extracted when necessary. Problem is, if I use a function in the library.au3 in another script which doesn't require this dependent file, as I am including the whole file using include tag, it is embedding that file also. Is there any way to exclude that.
  5. Hi guys, I need a little help here I have this simple Powershell script, that is able to set "sig.htm" as signature in OWA for the mail account specified. First part of the script just loads the Exchange snapin, since this is needed for the Get-Mailbox command. #Add Exchange 2010/2013 snapin if not already loaded in the PowerShell session if (!(Get-PSSnapin | where {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"})) { try { Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction STOP } catch { #Snapin was not loaded Write-Warning $_.Exception.Message EXIT } . $env:ExchangeInstallPath\bin\RemoteExchange.ps1 Connect-ExchangeServer -auto -AllowClobber } $mailboxes = Get-Mailbox -Identity $mailboxes| foreach {$file= "sig.htm"; Set-MailboxMessageConfiguration -identity $_.alias -SignatureHtml "$(Get-Content -Path $file -ReadCount 0)"} What I want is for AutoIt to use Powershell.exe to run the script somehow. This way I would be able to use AutoIt variables and arrays together with the PS script. I guess the solution would be to run Powershell.exe with command line arguments? If that is not possible, maybe have the script stored as a "ps1" file, and interact with it that way? (not preferred)
  6. Powershell - COM Many Windows Business Application are now only supporting Powershell, as a scripting environment. Like MS Exchange / SharePoint / Active Directory / MS SQL / etc. This makes Au3 a handicapped scripting environment for administrators to work with. But hold on ! Since 2008 Sapien Technologies has released a Powershell COM component named ActiveXPoSH, that makes the bridge between all Download here First register an account before getting the download access Why would you need Au3 to join PS1 ? Well it is a hell lot easier to create GUI's in AU3 than it is in PS1, so let's marry the 2. Here's an example script translated from there help file to AU3 ;************************************************************************** ; Copyright (c) SAPIEN Technologies, Inc. All rights reserved ; This file is part of the PrimalScript 2007 Code Samples. ; ; File: ActiveXposh.vbs ; ; Comments: ; ; Disclaimer: This source code is intended only as a supplement to ; SAPIEN Development Tools and/or on-line documentation. ; See these other materials for detailed information ; regarding SAPIEN code samples. ; ; THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY ; KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE ; IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A ; PARTICULAR PURPOSE. ;************************************************************************** #AutoIt3Wrapper_UseX64=N Dim $ActiveXPosh Const $OUTPUT_CONSOLE = 0 Const $OUTPUT_WINDOW = 1 Const $OUTPUT_BUFFER = 2 Func CreateActiveXPosh() Dim $success ; Create the PowerShell connector object $ActiveXPosh = ObjCreate("SAPIEN.ActiveXPoSH") $success = $ActiveXPosh.Init(False) ;Do not load profiles If $success <> 0 then Consolewrite( "Init failed" & @CR) endif If $ActiveXPosh.IsPowerShellInstalled Then Consolewrite( "Ready to run PowerShell commands" & @CR) Else Consolewrite( "PowerShell not installed" & @CR) EndIf ; Set the output mode $ActiveXPosh.OutputMode = $OUTPUT_CONSOLE EndFunc Func DownloadFile($URL,$Destination) Local $Return Dim $Command Dim $FSO ;Download a file with PowerShell $ActiveXPosh.Execute("$Client = new-object System.Net.WebClient") ;Note that variables are preserved between calls ; Construct a $Command $Command = "$Client.DownloadFile('" & $URL & "','" & $Destination & "')" ConsoleWrite ("Downloading ..." & @CR) $ActiveXPosh.Execute($Command) $FSO = ObjCreate("Scripting.FileSystemObject") If $FSO.FileExists($Destination) Then ConsoleWrite ("File transfer complete" & @CR) Else ConsoleWrite ("File Transfer failed" & @CR) EndIf Return $Return EndFunc Func ListServices() Dim $outtext ; Set the $OUTPUT mode to $BUFFER $ActiveXPosh.OutputMode = $OUTPUT_BUFFER $ActiveXPosh.Execute("Get-WmiObject -class Win32_Service | Format-Table -property Name, State") ; Get the $OUTPUT line by line and add it to a variable For $str In $ActiveXPosh.OUTPUT() $outtext = $outtext & $str $outtext = $outtext & @CRLF Next ; Alternatively you can get the $OUTPUT as a single String ; $outtext = $ActiveXPosh.OutputString ConsoleWrite ($outtext & @CR) $ActiveXPosh.ClearOutput() ; Empty the $OUTPUT $BUFFER EndFunc ; Create the actual Object CreateActiveXPosh() $Status = $ActiveXPosh.GetValue("(Get-Service UPS).Status") if($Status = "Stopped") then ConsoleWrite ("UPS Service is stopped" & @CR) else ConsoleWrite ("UPS Service is " & $Status & @CR) EndIf ; List all running processes using PowerShell $ActiveXPosh.Execute("Get-Process") ; Check if WinWord is running using PowerShell if $ActiveXPosh.Eval("get-process winword") = 1 Then ConsoleWrite ("Microsoft Word is running" & @CR) Else ConsoleWrite ("Microsoft Word is not running" & @CR) EndIf DownloadFile ("[url="","C:\Temp\activexposh.pdf"]","C:\Temp\activexposh.pdf[/url]") ; Use ListServices to show all services in this machine using PowerShell() ListServices() ConsoleWrite ("Version " & $ActiveXPosh.GetValue("$PSHOME") & @CR) $ActiveXPosh = "" Example how to load a PS1 command file #AutoIt3Wrapper_UseX64=N Dim $ActiveXPosh Const $OUTPUT_CONSOLE = 0 Const $OUTPUT_WINDOW = 1 Const $OUTPUT_BUFFER = 2 Func CreateActiveXPosh() Local $success ; Create the PowerShell connector object $ActiveXPosh = ObjCreate("SAPIEN.ActiveXPoSH") $success = $ActiveXPosh.Init(False) ;Do not load profiles If $success <> 0 then Consolewrite( "Init failed" & @CR) endif If $ActiveXPosh.IsPowerShellInstalled Then Consolewrite( "Ready to run PowerShell commands" & @CR & @CR) Else Consolewrite( "PowerShell not installed" & @CR & @CR) EndIf ; Set the output mode $ActiveXPosh.OutputMode = $OUTPUT_CONSOLE $ActiveXPosh.OutputWidth = 250 EndFunc ; Create the actual Object CreateActiveXPosh() $PS1 = FileOpenDialog("Open PS1 Script", @ScriptDir & "\", "PS Scripts (*.ps1)") PowerShell_Script($PS1) Func PowerShell_Script($hPSFile) $file = FileOpen($hPSFile, 0) ; Open read only If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf Local $sCmd While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $sCmd &= $line & @CRLF Wend ; ConsoleWrite("Line read: " & @CRLF & $sCmd & @CRLF) FileClose($file) ExecuteCMD($sCmd) EndFunc Func ExecuteCMD($sPSCmd) Dim $outtext ; Set the $OUTPUT mode to $BUFFER $ActiveXPosh.OutputMode = $OUTPUT_BUFFER $ActiveXPosh.Execute($sPSCmd) ; Get the $OUTPUT line by line and add it to a variable For $str In $ActiveXPosh.OUTPUT() $outtext = $outtext & $str $outtext = $outtext & @CRLF Next ; Alternatively you can get the $OUTPUT as a single String ; $outtext = $ActiveXPosh.OutputString ConsoleWrite ($outtext & @CR) $ActiveXPosh.ClearOutput() ; Empty the $OUTPUT $BUFFER EndFunc I am running this from component from my Windows 7 x64 bit Powershell 3.0 version, and it still is working fine. Enjoy ! ptrex
  7. Hi experts. I'm trying to get this to work: but I get an error: error: syntax error (illegal character) "Import-Module .\" Can anyone help me?
  8. I'm having a heck of a time trying to figure out how to call/invoke a WMI method through Autoit. I have a Powershell script that checks if a reboot is required using multiple checks including a WMI method related to ConfigMgr/SCCM but I want to do this in Autoit because I have a script that does other things and prompts the user to reboot if needed. I've given up on trying to make Autoit run the Powershell script and capture the true/false return value so since I know how to do everything the Powershell script does in Autoit, minus this WMI method call, I figured I'd take a stab at doing all of it in Autoit. The WMI method involved is called DetermineIfRebootPending in the root\ccm\ClientSDK namespace in the CCM_ClientUtilities class. I've done some searching on the forums here and saw many references to the Scriptomatic so I downloaded that and when I run it, since (I'm guessing) there are no properties in the CCM_ClientUtilities class, it doesn't show up as an available option in the class dropdown (see attached image), so it doesn't seem like Scriptomatic is going to help me here unless I'm missing something. Here is the Powershell part that I'd like to convert to Autoit. $CCMClientSDK = $null $CCMSplat = @{      NameSpace='ROOT\ccm\ClientSDK'      Class='CCM_ClientUtilities'      Name='DetermineIfRebootPending'      ComputerName=$ComputerName      ErrorAction='SilentlyContinue' } $CCMClientSDK = Invoke-WmiMethod @CCMSplat If ($CCMClientSDK.IsHardRebootPending -or $CCMClientSDK.RebootPending) {      $SCCMReboot = $true } So as you can see, its invoking the DetermineIfRebootPending method and then checking the IsHardRebootPending and RebootPending properties to see if they are True or False. If either are true, it sets the $SCCMReboot to true and later on down the script, it returns that value to the pipeline after checking some other registry locations to determine if reboot is required. If anyone could help me either 1) convert the above code to Autoit or 2) figure out how to run the powershell script from within Autoit and capture the return value, I'd be forever grateful. Thanks!
  9. Hello, Currently I am running a script that calls a powershell script. To read the results of that I am reading StdOut. I am parsing things accordingly but unfortunately it doesn't parse correctly all the time and I end up missing parts of the string or other problems. My question then is, what is the best results for reading what is returned when running a powershell script or something similar?
  10. Hi guys, This is probably an obvious one, but I really don't use this command at all so am hoping you can spot my mistake. I'm running a powershell script on a schedule with the following script in a function, the function is being called in a loop, but the console process is not closing in the background and I end up with a bunch of console windows running in the background: Run(@comspec & ' /k PowerShell.exe -STA -NonInteractive -ExecutionPolicy ByPass -Command "& ''Z:\Powershell\365\GetNextDetails.ps1'' "', "", @SW_HIDE) Thanks!
  11. !Arf it i used [Start new topic] when i was in GUI section and the post was moved without i even noticed it. Can an admin move that to general (SORRY)! Hello guys ME again and my ugly english xD. This is the only one powershell command i am not able to use becose i dont found a way to insert the USERNAME $Variable at the first line. i am not able to find a third way to QUOTE a variable when i use "*" for the AutoIt command and the '*' for the PS command but i need to QUOTE inside the '*'PS command my $Variable $iPid = run("powershell get-aduser -Filter {sn -eq 'USERNAME'} -Properties sAMAccountName,Title" , @WindowsDir , @SW_HIDE , 0x2) $AllInfo = "" While 1 $AllInfo &= StdoutRead($iPID) If @error Then ExitLoop EndIf WEnd $AllInfo = stringsplit($AllInfo , @LF , 2) ;split result in all @LF but don't use the splitted result for anything _ArrayDisplay($AllInfo) This gonna be my last question becose i can do all the rest (i guess & wish ) alone
  12. Hello. I improved my powershell skill like F**** !! I am so happy Level skill under beginner HAHA well i am just getting what i want but now i got a question about autoit + powershell When i run that Shellcommand $iPid = run("Powershell Get-ADUser USER -Properties * | select -Expand Title" , @WindowsDir , @SW_HIDE , 0x2) The return valu is : Micro r,seau (this is normal in PowerShell) Can i transform the value Micro réseau with autoit
  13. Hey Guys, I am almost there but feel I am missing something that is right in front of me and need another set of eyes. I am trying to run the following powershell file with the following parameters. This works in powershell just fine. Reset-LocalAdminPassword.ps1 -Password $secureString I created an autoit script to do a few other things but from venturing in the forums I found some code and did the following: ;THIS COMMAND WILL RUN THE powershell script $iDir = "C:\test\script\Reset-LocalAdminPassword.ps1" Run('cmd /k C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File ' & '"' & $iDir & '-Password $secureString') Sleep(15000) The problem is that when it runs it gives me a message that C:\test\script\Reset-LocalAdminPassword.ps1-Password $secureString' is not a valid ps1 file. I cannot seem to get it to run the ps1 file with the -Password $secureString' parameter. It keeps cobining the ps1 path and the parameters all as one. I am sure this is something I am overlooking but I have been battling with this for a few hours now and just don't know what I am missing.
  14. I have messed with this time to time, but recently decided to go ahead and push it out because I have so many people having the default reader app take over adobe and since they are not admins they cant easily change the default program to adobe for their profile. To remove the app for the current user I use. get-appxpackage | where name -like '*reader*' | remove-appxpackage If it is a new computer build I can remove the app from the system so it does not install for any new users with this. get-provisionedappxpackage -online | where displayname -like '*reader*' | remove-appxprovisionedpackage -online So where I am stuck is getting it off existing accounts on computers in the field. Every article, document, etc I can find says all you need to do is add the -allusers flag. If I add the flag to the get package part it does show the package for each user, but when I pipe it into the remove-package cmdlet I get an error that the package is not installed for the current user and it does not uninstall it for any other account. This is what I have tried: get-appxpackage -allusers | where name -like '*reader*' | remove-appxpackage Also a revision of it get-appxpackage -allusers *reader* | remove-appxpackage As far as I can tell, this is correct but simply is not working. Any ideas or anybody know what the key issue that I am overlooking is?
  15. This is a quick start guide to using the AutoIt PowerShell Cmdlets. The best bits of AutoIt directly from PowerShell The files you need are as follows (get them from the zip file or the Program Files folder after installation): AutoItX.psd1AutoItX3.PowerShell.dllAutoItX3.Assembly.dllAutoItX3.dllAutoItX3_x64.dllTo use the Cmdlets open a PowerShell cmd prompt and enter: Import-Module .\AutoItX.psd1 Now you can get a list of available AutoIt Cmdlets by doing Get-Command *AU3*: PS> Get-Command *AU3* Name Category Module ---- -------- ------ Invoke-AU3MouseWheel Cmdlet AutoItX Move-AU3Mouse Cmdlet AutoItX Invoke-AU3MouseClickDrag Cmdlet AutoItX Get-AU3MouseCursor Cmdlet AutoItX Invoke-AU3MouseUp Cmdlet AutoItX Assert-AU3WinActive Cmdlet AutoItX Assert-AU3WinExists Cmdlet AutoItX Assert-AU3IsAdmin Cmdlet AutoItX Invoke-AU3Shutdown Cmdlet AutoItX Send-AU3ControlKey Cmdlet AutoItX Invoke-AU3MouseDown Cmdlet AutoItX Invoke-AU3MouseClick Cmdlet AutoItX Invoke-AU3ControlTreeView Cmdlet AutoItX Invoke-AU3ControlListView Cmdlet AutoItX Invoke-AU3ControlCommand Cmdlet AutoItX Invoke-AU3ControlClick Cmdlet AutoItX Move-AU3Control Cmdlet AutoItX Set-AU3ControlText Cmdlet AutoItX Show-AU3Control Cmdlet AutoItX Hide-AU3Control Cmdlet AutoItX Get-AU3ControlText Cmdlet AutoItX Get-AU3ControlFocus Cmdlet AutoItX Set-AU3ControlFocus Cmdlet AutoItX Disable-AU3Control Cmdlet AutoItX Enable-AU3Control Cmdlet AutoItX Get-AU3StatusbarText Cmdlet AutoItX Invoke-AU3RunAsWait Cmdlet AutoItX Invoke-AU3RunAs Cmdlet AutoItX Invoke-AU3RunWait Cmdlet AutoItX Invoke-AU3Run Cmdlet AutoItX Set-AU3Clip Cmdlet AutoItX Get-AU3Clip Cmdlet AutoItX Set-AU3WinTrans Cmdlet AutoItX Set-AU3WinTitle Cmdlet AutoItX Set-AU3WinState Cmdlet AutoItX Set-AU3WinOnTop Cmdlet AutoItX Move-AU3Win Cmdlet AutoItX Show-AU3WinMinimizeAllUndo Cmdlet AutoItX Show-AU3WinMinimizeAll Cmdlet AutoItX Get-AU3WinState Cmdlet AutoItX Get-AU3WinProcess Cmdlet AutoItX Get-AU3WinClassList Cmdlet AutoItX Get-AU3WinCaretPos Cmdlet AutoItX Get-AU3WinClientSize Cmdlet AutoItX Get-AU3ControlPos Cmdlet AutoItX Get-AU3ControlHandle Cmdlet AutoItX Get-AU3MousePos Cmdlet AutoItX Get-AU3WinPos Cmdlet AutoItX Get-AU3WinHandle Cmdlet AutoItX Get-AU3ErrorCode Cmdlet AutoItX Initialize-AU3 Cmdlet AutoItX Show-AU3WinActivate Cmdlet AutoItX Close-AU3Win Cmdlet AutoItX Wait-AU3WinClose Cmdlet AutoItX Wait-AU3WinNotActive Cmdlet AutoItX Set-AU3Option Cmdlet AutoItX Send-AU3Key Cmdlet AutoItX Wait-AU3Win Cmdlet AutoItX Wait-AU3WinActive Cmdlet AutoItX Get-AU3WinTitle Cmdlet AutoItX Get-AU3WinText Cmdlet AutoItX I’ll show how to use the Cmdlets using a simple example that will open notepad.exe and modify the edit window by setting the text and simulating some keystrokes. First create a blank PowerShell script called notepad_example.ps1 in the same folder as the AutoItX components above and open it for editing. Now we want to import the PowerShell module which is AutoItX.psd1. Enter the following in the script: Import-Module .\AutoItX.psd1 We want to run notepad.exe: Invoke-AU3Run -Program notepad.exe After notepad opens we want to wait for the notepad “Untitled -Notepad” window to appear. You might need to change the title for non-English versions of Windows: $notepadTitle = "Untitled - Notepad" Wait-AU3Win -Title $notepadTitle $winHandle = Get-AU3WinHandle -Title $notepadTitle Get-AU3WinHandle returns a native Win32 handle to the notepad window. We can use this handle in many other AutoIt functions and it uniquely identifies the window which is much more reliable than constantly using a windows title. If you have obtained a window handle using any other Win32 function you can use it with AutoIt. After obtaining the handle to the notepad window we want to ensure that the window is active and then get a handle to the Edit Control. Using the AU3Info.exe tool that comes with AutoIt we can find that the name of the edit control in notepad is Edit1. Show-AU3WinActivate -WinHandle $winHandle $controlHandle = Get-AU3ControlHandle -WinHandle $winhandle -Control "Edit1" Now that we have a handle to the edit control we can set text in two ways: Directly (Set-AU3Controltext) or with simulated keystrokes (Send-AU3ControlKey): Set-AU3ControlText -ControlHandle $controlHandle -NewText "Hello! This is being controlled by AutoIt and PowerShell!" -WinHandle $winHandle Send-AU3ControlKey -ControlHandle $controlHandle -Key "{ENTER}simulate key strokes - line 1" -WinHandle $winHandleNow let’s see what the entire script looks like: # Import the AutoIt PowerShell module Import-Module .\AutoItX.psd1 # Run notepad.exe Invoke-AU3Run -Program notepad.exe # Wait for an untitled notepad window and get the handle $notepadTitle = "Untitled - Notepad" Wait-AU3Win -Title $notepadTitle $winHandle = Get-AU3WinHandle -Title $notepadTitle # Activate the window Show-AU3WinActivate -WinHandle $winHandle # Get the handle of the notepad text control for reliable operations $controlHandle = Get-AU3ControlHandle -WinHandle $winhandle -Control "Edit1" # Change the edit control Set-AU3ControlText -ControlHandle $controlHandle -NewText "Hello! This is being controlled by AutoIt and PowerShell!" -WinHandle $winHandle # Send some keystrokes to the edit control Send-AU3ControlKey -ControlHandle $controlHandle -Key "{ENTER}simulate key strokes - line 1" -WinHandle $winHandle Send-AU3ControlKey -ControlHandle $controlHandle -Key "{ENTER}simulate key strokes - line 2" -WinHandle $winHandle Send-AU3ControlKey -ControlHandle $controlHandle -Key "{ENTER}{ENTER}" -WinHandle $winHandle This is how the notepad window should look if everything is working correctly:
  16. I'm running AutoIT v3.3.14.2 on Windows 10 ver 1511. The September Cumulative Update from Microsoft has broken the way some third party credential providers work. You can see more detail here: So I want to automatically and silently remove this update from all our machines. In Windows 7 I could easily do it with this: wusa.exe /uninstall /kb:3185614 /quiet But apparently Microsoft has taken away the /quiet switch functionality in Windows 10. wusa /? will show that the switch is there, but when trying to use it error 87 (invalid parameter) is returned. So I relented on that point and decided to run wusa without the quiet switch. It pops up a child window that prompts for confirmation before uninstalling the update. Sounds like a perfect job for AutoIT, right? Except I can't get the button to click, either using ControlClick or ControlSend or Send. I can select it by sending the {Alt} key to it and it highlights. But I just can't get it to accept the click or {Enter}. I then tried using Powershell and DISM to remove the package, but this is a hotfix and doesn't have a package name, so I can't use dism /remove-package, either. Does anybody have any other ideas how this can be done silently?
  17. I have a rather heady PowerShell script that requires a few inputs that I would like to present as pick lists/pull down lists. I've fiddled with doing this using Windows API calls and frankly it's pretty ugly and non-productive. What I'd like to accomplish is to present the user with a refined UI that will force them to color between the lines and catch any error putput and display it to them in an organized fashion. Has anyone done this? I'd like to have an AutoIT based solution as my current client didn't plan on any extra time or budget to accomplish this task. Thanks, -Scott.
  18. #include<array.au3> _ArrayDisplay(_GetCertByThumb("")) ;~ "A1B9894B9BB100F43A229D65CC3C306FBF0BB9F8" Func _GetCertByThumb($sThumbprint = "") $sCommands = 'Powershell get-childitem -Path Cert:\CurrentUser -Recurse -Name | FindStr /L "\\"' & $sThumbprint $iPID = Run(@ComSpec & " /c " & $sCommands, "", @SW_HIDE , $stdout_child) $sOutput = "" While 1 $sOutput &= StdoutRead($iPID) If @error Then ExitLoop EndIf WEnd $aRtn = stringsplit($sOutput , @LF , 2) _ArrayDelete($aRtn , ubound($aRtn) - 1) If ubound($aRtn) < 1 then _ArrayAdd($aRtn , "No Match Found") Return $aRtn EndFunc
  19. I'm writing a set of PowerShell scripts/library for Windows 10 builds. One thing I often want to do is to browse to the location of a script that is part of a larger group of scripts and run it manually to do an install or make a one off change. So I like all my scripts to work well whether run from a task sequence or double-clicked in explorer. Most of my build scripts rely on having admin rights so I like to make them able to self-elevate if required - or at least give an error message. In PowerShell 4.0 (Windows 8.1) they added the #Requires -RunAsAdministrator statement but this won't do it for you - it just causes the script to abort if not admin. Below is a PowerShell script that does the following: Checks for admin rights using the Test-IsAdmin functionIf not admin:Get the full script path and working directory using the Get-UNCFromPath functionIf the paths are mapped drives then get the UNC version (drive mappings are lost when elevating from user to admin in most configurations)Execute PowerShell.exe with the UNC path of the script and the RunAs verb to trigger elevation. ExecutionPolicy is also set to Bypass on the command line. The working directory is also set to the UNC path version.Waits for the new process to finish, and captures its return codeExits using the same return codeScript is as follows: # Test if admin function Test-IsAdmin() { # Get the current ID and its security principal $windowsID = [System.Security.Principal.WindowsIdentity]::GetCurrent() $windowsPrincipal = new-object System.Security.Principal.WindowsPrincipal($windowsID) # Get the Admin role security principal $adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator # Are we an admin role? if ($windowsPrincipal.IsInRole($adminRole)) { $true } else { $false } } # Get UNC path from mapped drive function Get-UNCFromPath { Param( [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)] [String] $Path) if ($Path.Contains([io.path]::VolumeSeparatorChar)) { $psdrive = Get-PSDrive -Name $Path.Substring(0, 1) -PSProvider 'FileSystem' # Is it a mapped drive? if ($psdrive.DisplayRoot) { $Path = $Path.Replace($psdrive.Name + [io.path]::VolumeSeparatorChar, $psdrive.DisplayRoot) } } return $Path } # Relaunch the script if not admin function Invoke-RequireAdmin { Param( [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)] [System.Management.Automation.InvocationInfo] $MyInvocation) if (-not (Test-IsAdmin)) { # Get the script path $scriptPath = $MyInvocation.MyCommand.Path $scriptPath = Get-UNCFromPath -Path $scriptPath # Need to quote the paths in case of spaces $scriptPath = '"' + $scriptPath + '"' # Build base arguments for powershell.exe [string[]]$argList = @('-NoLogo -NoProfile', '-ExecutionPolicy Bypass', '-File', $scriptPath) # Add $argList += $MyInvocation.BoundParameters.GetEnumerator() | Foreach {"-$($_.Key)", "$($_.Value)"} $argList += $MyInvocation.UnboundArguments try { $process = Start-Process PowerShell.exe -PassThru -Verb Runas -Wait -WorkingDirectory $pwd -ArgumentList $argList exit $process.ExitCode } catch {} # Generic failure code exit 1 } } # Relaunch if not admin Invoke-RequireAdmin $script:MyInvocation # Running as admin if here $wshell = New-Object -ComObject Wscript.Shell $wshell.Popup("Script is running as admin", 0, "Done", 0x1) | Out-Null
  20. Hi, I would like to install chocolatey packages (OneGet) via Autoit. Manually without Autoit I would just open Powershell and use this command: Install-Package -Name Firefox -Force It also works with cmd (see attachment 1) powershell.exe -Command Install-Package -Name Firefox -Force With Autoit I tried the following code: RunWait(@ComSpec & ' /k ' & 'powershell.exe -Command Install-Package -Name Firefox -Force', @SW_SHOW) It doesnt work at all. I don't even see a cmd window. When I add @SystemDir the Windows appears with the error in attechment 2. Is there another way to run PowerShell Commands with Autoit? I would like to avoid starting Powershell, waiting for the window, sending the command and sending Enter. Thanks Eggsplorer
  21. Message is broken out further and requires extra massaging, that and I am formatting it for eventual Neo4j graph sexiness. #include <AutoItConstants.au3> #include<array.au3> #RequireAdmin $outfile = "test_PS_csv_failures.csv" If fileexists($outfile) then FileDelete($outfile) $iPID = run("powershell get-eventlog -logname security -Message '*An account failed to log on*' | select Index,TimeGenerated,Message | format-list" , "", @SW_HIDE , $stdout_child) $sOutput = "" While 1 $sOutput &= StdoutRead($iPID) If @error Then ExitLoop EndIf WEnd $aStr = stringsplit($sOutput , @CRLF , 3) For $i = ubound($aStr) - 1 to 0 step - 1 If NOT stringinstr($aStr[$i] , ":") Then _ArrayDelete($aStr , $i) Next ;~ _ArrayDisplay($aStr) $sFinal = "" $sLine = "" $k = 0 for $i = 0 to 29 $sLine &= stringregexpreplace(stringstripws($aStr[$i] , 8) , "(\:.*)" , "") & "," next $sFinal &= StringTrimRight($sLine , 1) & @LF $sLine = "" for $i = 30 to ubound($aStr) - 1 $aStr[$i] = stringreplace($aStr[$i] , "," , "_") $sLine &= stringregexpreplace($aStr[$i] , "(\A.*\D:)" , "") & "," $k += 1 If $k = 30 Then If NOT StringInStr($sLine , @UserName) Then $sFinal &= StringTrimRight($sLine , 1) & @LF $sLine = "" $k = 0 EndIf next ;~ msgbox(0, '' , $sFinal) filewrite($outfile , $sFinal) shellexecute($outfile)
  22. Is there a way to be able to filter like power can filter? Like the way this powershell script filters for instance: Import-Module ActiveDirectory Get-ADUser -Filter {EmailAddress -eq "$Usersemailaddress"}| Select-Object -ExpandProperty SamAccountName | Out-File C:\Users\"$env:username"\Desktop\email2samconversion.txt Goal is trying to get the SamAccountName by filtering with the email address of a user in AD. I have the AD.UDF but it only works with the Sam and the FQDN. i've tried running powershell in Autoit, but it takes at least 7 seconds to start Powershell>import the module>create the text file>read the text file>Delete the textfile from desktop>Display in Edit box in GUI. I'm wondering if there is a way to filter the search function of AD through autoit kind of like how Powershell does. i've not yet been able to powershell to run properly in Autoit either: I tried: Run(powershell -Command Import-Module ActiveDirectory | Get-ADUser -Filter {mail -eq "$UserEmail"} | Select-Object -ExpandProperty SamAccountName | Out-File C:\users\$env:username\desktop\SamaccountNametextfile.txt") But it keeps failing. I tried using ShellExecute as well and neither of them worked.
  23. I need a function where it will get a string as parameter which will of syntax in VBScript like below a&"asdasd"&asd&"as&dsf&gdf"&fs Here in the above string what ever in the quotes we shouldn't replace them as they are taken as normal strings.And if the ampersand(&) if outside the quotes then we need to replace them with plus(+).And the normal words which are outside the quotes we need to append them with $. So the output will be as below. $a+"asdasd"+$asd+"as&dsf&gdf"+$fs. Can you please help me on this.I'm unable to differentiate with & in the quotes and outside the quotes. Don't know how to check whether a string is in quotes or not.
  24. Hello Everyone, I was just made aware of the free PowerShell App Deployment Toolkit and wanted to share it here. One could fairly easily customize this toolkit by adding the AutoItX DLL/COM control to it thereby utilizing the AutoIt PowerShell CmdLets making it a complete solution for all types of deployments! Regards, TXTechie
  25. I'm not familar with popweshell ,could someone help me translate the code below to autoit ? thanks in advance. $priPath = $args[0] $outputPath = $args[1] $replacementPath = $args[2] $ErrorActionPreference = "Stop" $inputStream = [System.IO.File]::OpenRead($priPath) $outputStream = [System.IO.File]::Create($outputPath) $replacementStream = [System.IO.File]::OpenRead($replacementPath) $inputReader = New-Object System.IO.BinaryReader -ArgumentList $inputStream $outputWriter = New-Object System.IO.BinaryWriter -ArgumentList $outputStream $inputStream.CopyTo($outputStream) $replacementLengthAligned = ([Math]::Ceiling($replacementStream.Length / 8) * 8) # header $inputStream.Seek(0x14, "Begin") | Out-Null $headerLength = $inputReader.ReadUInt32() $inputStream.Seek(0xB8, "Begin") | Out-Null $dataitemOffset = $inputReader.ReadUInt32() $origDataitemLength = $inputReader.ReadUInt32() $dataitemLength = $origDataitemLength + $replacementLengthAligned $outputStream.Seek(0xBC, "Begin") | Out-Null $outputWriter.Write([int]$dataitemLength) # dataitem $outputStream.Seek($headerLength + $dataitemOffset + 0x18, "Begin") | Out-Null $outputWriter.Write([int]$dataitemLength) $inputStream.Seek($headerLength + $dataitemOffset + 0x24, "Begin") | Out-Null $stringCount = $inputReader.ReadUInt16() $blobCount = $inputReader.ReadUInt16() $origDataLength = $inputReader.ReadUInt32() $outputStream.Seek(0xC, "Current") | Out-Null $outputWriter.Write([int]($origDataLength + $replacementLengthAligned)) $outputStream.Seek($stringCount * 4, "Current") | Out-Null for ($i = 0; $i -lt 10; $i++) { $outputWriter.Write($origDataLength) $outputWriter.Write([int]$replacementStream.Length) } $outputStream.Seek(($blobCount - 10) * 8, "Current") | Out-Null # data $outputStream.Seek($origDataLength, "Current") | Out-Null if ($outputStream.Length - $outputStream.Position -ne 0x18) { Write-Error "Not compatible with this PRI file." } $replacementStream.CopyTo($outputStream) # footer $outputStream.Seek($replacementLengthAligned - $replacementStream.Length, "Current") | Out-Null $outputWriter.Write(0xDEF5FADE) $outputWriter.Write([int]$dataitemLength) $outputWriter.Write(0xDEFFFADE) $outputWriter.Write(0x00000000) $outputWriter.Write([char[]]"mrm_pri2") $outputStream.Seek(0xC, "Begin") | Out-Null $outputWriter.Write([int]$outputStream.Length) $outputStream.Seek(-0xC, "End") | Out-Null $outputWriter.Write([int]$outputStream.Length) $inputReader.Close() $outputWriter.Close() $replacementStream.Close()