Hi guys,
how can I execute the following script on a remote machine:
$wshell =New-Object-ComObject wscript.shell; $wshell.AppActivate('title of the application window')Sleep1 $wshell.SendKeys('q')I tried it with a function:$a ={functionClose_window{ $wshell =New-Object-ComObject wscript.shell; $wshell.AppActivate(‘name of the window’)Sleep2 $wshell.SendKeys('q')}Close_window($args)} $user ='user' $pw ='password' $password =ConvertTo-SecureString $pw -asplaintext -force $credential =New-ObjectSystem.Management.Automation.PSCredential $user, $password $servers =Get-content D:\test.txt foreach ($server in $servers){ $session =New-PSSession-ComputerName $server -Credential $credential invoke-command -session $session -ScriptBlock $a}
I also found this:
$scriptobjects =@()
$scriptobjects +={
$wshell =New-Object-ComObject wscript.shell;
$wshell.AppActivate(‘Untitled-Notepad’)Sleep2
$wshell.SendKeys('q')}
$scriptobjects |foreach {& $_}
but I did not manage it to run on a remote machine, the result is always FALSE :-(
I would be happy if someone could help me with this!
Many thanks in advance
Paul