powershell

Sara 441 Reputation points
2021-07-02T09:22:47.94+00:00

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 for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Answer accepted by question author
  1. Anonymous
    2021-07-02T09:40:25.28+00:00

    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.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.