question

Sara925 avatar image
0 Votes"
Sara925 asked MotoX80 commented

powershell

Have the below script which is to execute a .exe, but running into error ,

"Cannot Validate Argument On Parameter 'ComputerName' 111316-image.png What am I missing here?



Start-Transcript -path C:\temp\Connect.txt -Append
$servernames = get-content C:\Temp\Servers.txt

foreach ($servername in $servernames)
{
$servername
$remotesession = New-PSSession -ComputerName $servername

Invoke-Command -Session $remotesession -ScriptBlock { Start-Process -FilePath 'C:\Program Files (x86)\Enterprise\Client\client.exe' }
Write-Host "client invoked"
}

Remove-PSSession -Session $remotesession

Stop-Transcript


windows-server-powershell
image.png (322.6 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered MotoX80 commented

Hi,

The script looks OK to me. Have you checked $servernames or the file C:\Temp\Servers.txt?

Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Not sure what happened there, it didn't work in the server where I was testing , but works in other server without any error but the .exe does not opens up, just finishes successfully.

Invoke-Command -Session $remotesession -ScriptBlock { Start-Process -FilePath 'C:\Program Files (x86)\Enterprise\Client\client.exe' }
Write-Host "client invoked"


Does start-process works in multiple servers?

0 Votes 0 ·

Does start-process works in multiple servers?

There should not be a problem with start-process as long as the .exe exists. Use Test-Path to verify that client.exe is on that particular server. Then check task manager to verify that the process is running. Or add a "get-process -name client" to the scriptblock.

Remember that Invoke-Command is in an unattended session on the remote computer, so if you were expecting to see a GUI window from the app on the desktop , that won't happen.

0 Votes 0 ·