[CmdletBinding()] param( [string[]]$ComputerName, [PSCredential]$Credential, [string]$DomainController = $env:COMPUTERNAME, [switch]$RefreshPolicy ) $ErrorActionPreference = 'Stop' if (-not $ComputerName) { Import-Module ActiveDirectory $ComputerName = @(Get-ADComputer -Server $DomainController -Filter 'Enabled -eq $true' -Properties OperatingSystem,DNSHostName | Where-Object { $_.DNSHostName -and $_.OperatingSystem -like 'Windows*' -and $_.OperatingSystem -notlike '*Server*' } | Select-Object -ExpandProperty DNSHostName) } foreach ($name in $ComputerName) { try { $parameters = @{ComputerName=$name;Authentication='Kerberos';ErrorAction='Stop'; SessionOption=(New-PSSessionOption -OpenTimeout 10000 -OperationTimeout 90000)} if ($Credential) { $parameters.Credential = $Credential } Invoke-Command @parameters -ArgumentList ([bool]$RefreshPolicy) -ScriptBlock { param($refresh) $exitCode = $null if ($refresh) { gpupdate /target:computer /force /wait:60 | Out-Null; $exitCode=$LASTEXITCODE } $rules = @(Get-NetFirewallRule -PolicyStore ActiveStore -Name 'LaSalle-Management-*' -ErrorAction SilentlyContinue | Where-Object { $_.PolicyStoreSourceType -eq 'GroupPolicy' -and $_.Enabled -eq 'True' }) $applied = @(Get-CimInstance -Namespace root\RSOP\Computer -ClassName RSOP_GPO) [pscustomobject]@{ Name=$env:COMPUTERNAME; Reachable=$true; SecureChannel=(Test-ComputerSecureChannel) PolicyApplied=($applied.Name -contains 'La Salle - Workstation remote management') RdpEnabled=((Get-ItemPropertyValue 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server' -Name fDenyTSConnections) -eq 0) NLA=((Get-ItemPropertyValue 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name UserAuthentication) -eq 1) WinRM=[string](Get-Service WinRM).Status; RdpService=[string](Get-Service TermService).Status PolicyFirewallRules=$rules.Count; GpUpdateExit=$exitCode } } | Select-Object Name,Reachable,SecureChannel,PolicyApplied,RdpEnabled,NLA,WinRM,RdpService,PolicyFirewallRules,GpUpdateExit } catch { [pscustomobject]@{Name=$name;Reachable=$false;Error=$_.Exception.Message} } }