top of page

PowerShell WinRM Test


<#

      ScriptsByScott.com

    .Synopsis

       Test to quickly check winRM acess to machines

    .DESCRIPTION

       Takes input from text file and runs function to test WinRm

    .EXAMPLE

       WinRM-Status $ComputerList

#>

 

#------------------------------------------------------------------------ Start Function -------------------------------------------------------------------------

    Function WinRM-Status($Computers){

        #Test Path to each system and throttle limit of concurrnet processes to 256

        $WinRMJob = Invoke-Command -ScriptBlock {Test-Path "C:\"} -ComputerName $Computers  -ThrottleLimit 256 -AsJob | Wait-Job

        #Group the results together, then sort into 2 string arrays with servername only

        $Grouped = $WinRMJob.ChildJobs | Group-Object -Property State

        #Pulls Successfule items to one array

        [Array]$WinrmSuccess = ($Grouped | where {$_.Name -eq "Completed"}).Group | %{$_.Location}

        #Pulls Failed Items to another array

        [Array]$noWinrm = Compare-Object -ReferenceObject $Computers -DifferenceObject $WinrmSuccess | Select-Object -ExpandProperty  Inputobject -ErrorAction SilentlyContinue

        #Assigns Array values to object

        $properties = @{              

                    WinRMFails = $noWinrm;              

                    WinRMPass = $WinrmSuccess;                   

        }

 

        #Create Object and Assign to Var

        $ReturnObj = New-Object -TypeName PSObject -Property $properties

 

        #Returns the Value

        Return $ReturnObj

    }

 

#------------------------------------------------------------------------ End Function -------------------------------------------------------------------------

​

​

​

    #Get Computer List Input - Text File Can Easily Be Replaced with a Get-ADComputer Query.

    $ComputerList=Get-Content C:\temp\MyComputers.txt

 

    #Call Function

    $Results=WinRM-Status $ComputerList

 

    #Output to Screen of WinRM Accessible Systems

    Write-Output "Systems that Passed"

    $Results.WinRMPass

 

    #Output to Screen of Failed Access to Systems

    Write-Output "Systems that Failed"

    $Results.WinRMFails

bottom of page