Last active
November 14, 2017 04:03
-
-
Save techthoughts2/d313d241dcc4ead2d5ec to your computer and use it in GitHub Desktop.
Verifies if remote WinRM Powershell commands can be run against another device by verifying WinRM connectivity to the specified computer name over both HTTP and HTTPS. Returns a customer PSObject containing boolean value for both HTTP and HTTPS results.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.Synopsis | |
Tests WinRm connectivity to specified computername via HTTP and HTTPS | |
.DESCRIPTION | |
Evaluates both HTTP and HTTPS connectivity over WinRM to specified computername. Returns PSObject with Boolean value for HTTP and HTTPS based on results. | |
.PARAMETER ComputerName | |
Hostname of device you wish to test WinRM connection to | |
.EXAMPLE | |
Test-WinRM -ComputerName HYP1 | |
Tests HTTP and HTTPS WinRM connectivity to HYP1 and returns two boolean values in PSObject | |
.EXAMPLE | |
Test-WinRM -ComputerName HYP1 -Verbose | |
Tests HTTP and HTTPS WinRM connectivity to HYP1 and returns two boolean values in PSObject. Verbose output is displayed. | |
.OUTPUTS | |
PSObject containing boolean values for HTTP and HTTPS WinRM results | |
.NOTES | |
Author: Jake Morrison | |
http://techthoughts.info | |
Only hostnames are supported by this simple WinRM check. IPs are not supported. | |
The default timeout is static set to 8 seconds and can be adjusted by changing the OperTimeout value. | |
#> | |
function Test-WinRM { | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory = $true, | |
Position = 0)] | |
[string]$ComputerName | |
) | |
[bool]$evalWinRMHTTP = $true #assume the best | |
[bool]$evalWinRMHTTPS = $true #assume the best | |
$Object = New-Object PSObject | |
$so = New-PSSessionOption -MaxConnectionRetryCount 2 -OpenTimeout 8000 | |
Write-Verbose -Message "Evaluating WinRM over HTTP..." | |
$eval = $null | |
$eval = New-PSSession -ComputerName $ComputerName -SessionOption $so -ErrorAction SilentlyContinue | |
if (!($eval)) { | |
$evalWinRMHTTP = $false | |
Write-Verbose -Message "HTTP: $evalWinRMHTTP" | |
} | |
Write-Verbose -Message "Evaluating WinRM over HTTPS..." | |
$eval = $null | |
$eval = New-PSSession -ComputerName $ComputerName -SessionOption $so -UseSSL -ErrorAction SilentlyContinue | |
if (!($eval)) { | |
$evalWinRMHTTPS = $false | |
Write-Verbose -Message "HTTPS: $evalWinRMHTTPS" | |
} | |
$Object | add-member Noteproperty HTTP $evalWinRMHTTP | |
$Object | add-member Noteproperty HTTPS $evalWinRMHTTPS | |
return $Object | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment