internal/Test-PSRemoting.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#requires -version 3.0
 
Function Test-PSRemoting {
<#
Jeff Hicks
https://www.petri.com/test-network-connectivity-powershell-test-connection-cmdlet
#>

    [cmdletbinding()]
    param(
    [Parameter(Position=0,Mandatory,ValueFromPipeline)]
    [DbaInstance]$ComputerName,
    $Credential = [System.Management.Automation.PSCredential]::Empty,
    [switch][Alias('Silent')]$EnableException
    )

    process {
        Write-Message -Level VeryVerbose -Message "Testing $($ComputerName.Computername)"
        try {
            $r = Test-WSMan -ComputerName $ComputerName.ComputerName -Credential $Credential -Authentication Default -ErrorAction Stop
            $true
        }
        catch {
            Write-Message -Level Verbose -Message "Testing $($ComputerName.Computername)" -Target $ComputerName -ErrorRecord $_
            $false
        }

    } #Process

} #close function