Get-WinRMEnabledPCs.ps1

<#PSScriptInfo
 
.VERSION 1.0.3
 
.GUID ad6d9ee1-7ef3-477b-8378-bb72b8b64fa3
 
.AUTHOR Kalichuza
 
.COMPANYNAME
 
.COPYRIGHT
 
.TAGS
 
.LICENSEURI
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
 
 
.PRIVATEDATA
 
.DESCRIPTION Uses the AD module to test if all domain joined machines will respond to a ping and then if winrm is enabled.
 
 
#>

<#
 
.DESCRIPTION
Uses the AD module to test if all domain joined machines will respond to a ping and then if winrm is enabled.
 
#>

param (
    [switch]$Output
)

$computers = Get-ADComputer -Filter * | Select-Object -ExpandProperty Name
$results = @()

foreach ($computer in $computers) {
    if (Test-Connection -ComputerName $computer -Count 1 -Quiet) {
        try {
            Test-WSMan -ComputerName $computer -ErrorAction Stop | Out-Null
            $status = [PSCustomObject]@{
                ComputerName = $computer
                WinRMStatus  = "Enabled"
            }
        } catch {
            $status = [PSCustomObject]@{
                ComputerName = $computer
                WinRMStatus  = "Disabled or Inaccessible"
            }
        }
    } else {
        $status = [PSCustomObject]@{
            ComputerName = $computer
            WinRMStatus  = "Offline"
        }
    }
    $results += $status
}

if ($Output) {
    $results | Export-Csv -Path "WinRM_Status.csv" -NoTypeInformation
}

$results