powershell

Sara 401 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 Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,407 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 31,171 Reputation points Microsoft Vendor
    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