Test-PSRemoting.psm1
<#
.SYNOPSIS Check PSRemoting state on remotes computers. .DESCRIPTION When you’re writing a script that depends on PowerShell Remoting, it’s often helpful to know that the remoting channel is open and will support the activities of your script. PowerShell has a Test-WSMan command, but that only verifies that a WSMan connection is possible. There are other scenarios you could be impacted by: -Not having permission on the remote machine -Misconfiguration of the PowerShell endpoint -Corrupted installation -(etc) As you dig deeper, you realize that the only way to really test the viability of the remoting channel is to just do something on it, and verify that you got the results you expected to. Since the implementation was so simple, we didn’t write a cmdlet for it. In retrospect, the concept is more difficult than the implementation, so we probably should have written it anyways. Here’s an example function that tests the remoting connection to a specific machine. .INPUTS One or more Computers objects. .OUTPUTS Returns True if PSRemoting is working or False if it doesn't. If you target more than one computer, it only returns True if PSRemoting is working on all of them. .NOTES This module is an adaptation of function made by Lee Holmes found on related link. All credit for him. I just brought it to the PowerShell Gallery to get it always online and ready for install anywhere. Improvements: -Full Help -Multi string input .LINK http://www.leeholmes.com/blog/2009/11/20/testing-for-powershell-remoting-test-psremoting/ .EXAMPLE PS C:\> Test-PSRemoting -ComputerName working-computer True Checking one computer where PSRemoting is working. .EXAMPLE PS C:\> Test-PSRemoting -ComputerName notworking-computer False Checking one computer where PSRemoting is NOT working. .EXAMPLE PS C:\> Test-PSRemoting -ComputerName working-computer, notworking-computer False Checking more than one computer where PSRemoting is NOT working at least in one of them. #> function Test-PSRemoting { param( [Parameter(Mandatory = $true)] [String[]]$ComputerName ) try { $errorActionPreference = "Stop" $result = Invoke-Command -ComputerName $computername { 1 } } catch { Write-Verbose $_ return $false } ## I've never seen this happen, but if you want to be ## thorough.... if($result -ne 1) { Write-Verbose "Remoting to $computerName returned an unexpected result." return $false } $true } |