I would like to create a script that tell the user whether or not PSRemoting is enabled on multiple remote machines. Here is what I have so far:
function Test-PSRemoting { Param( [Parameter(Mandatory=$True, ValueFromPipeline=$True)] [string[]] $ComputerName, [string] $Credential) $file = Read-Host "Enter file location for all error details: " try { $result = Invoke-Command -ComputerName $ComputerName -Credential $Credential { 1 } -ErrorAction SilentlyContinue -ErrorVariable Problem If ($Problem){ $result = 0} } catch { $result = 0} If ($result -eq 1){ write-host "PSRemoting is enabled on: " $ComputerName } else { write-host "PSRemoting is not enabled/working on: " $ComputerName $Problem | Out-File $file -Append} }
The function works perfect if I only specify one computer:
Test-PSRemoting -ComputerName Server1 - Credentials Admin
However, I cannot get the function to work if I specify multiple computers:
Test-PSRemoting -ComputerName Server1, Server2 - Credentials Admin Server1, Server2 | Test-PSRemoting -Credentials Admin