I am trying to execute a powershell script on a remote computer. The script opens a notepad application, creates a file and saves it. I run the script with below command in source machine:
Invoke-Command -ComputerName "na18actxdc" -ScriptBlock {D:\NMAutomation\trial_2.ps1}
The command runs for a long time on source machine and breaks. But the text file is not created. Could anyone help here please ?
However the same script when executed from the remote machine, executes faster and the text file gets saved. I have tried the same concept with autoit scripts and psexec options. None of them works.
Code on remote machine:
Import-Module "C:\Program Files (x86)\AutoIt3\AutoItX\AutoItX.psd1"
Invoke-AU3Run -Program notepad.exe
$windowtitle ="Untitled - Notepad"
Wait-AU3WinActive($windowtitle)
$windowhandle = Get-AU3WinHandle -Title $windowtitle
Show-AU3WinActivate -WinHandle $windowhandle
Send-AU3Key("I'm in notepad");
$windowhandle = Get-AU3WinHandle($windowtitle);
$controlHandle = Get-AU3ControlHandle -WinHandle $windowhandle -Control "Edit1"
Send-AU3ControlKey -ControlHandle $controlHandle -Key "{ENTER}simulate key strokes - line 1" -WinHandle $windowhandle
Close-AU3Win($windowtitle)
$windowtitlesaveas = "Save As"
$windowhandlesaveas = Get-AU3WinHandle ($windowtitlesaveas)
$controlHandlesaveas = Get-AU3ControlHandle -WinHandle $windowhandlesaveas -Control "Edit1"
$windowhandlesaveas -NewText "sample"
$controlHandlesaveas -Key "sample"
Invoke-AU3ControlClick -Title "Notepad" -Control "Button1" -NumClicks 1
Wait-AU3WinActive("Save As")
Set-AU3ControlText -Title "Save As" -Control "Edit1" -NewText "sample"
Send-AU3ControlKey -Title "Save As" -Control "Button1" -Key "{ENTER}"
Enter-PSSession -ComputerName na18actxdc
and thenD:\NMAutomation\trial_2.ps1
. I have a feeling that Autoit cmdlets that are meant for an interactive window will fail to work in a commandline session. - Sid