Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function Get-OnlineComputers() {
- param(
- [switch]
- $AllProperties
- )
- $pingTest = $null
- If($AllProperties){
- $computers = Get-ADComputer -Filter {Enabled -eq $true} -Property * -SearchBase "<SearchBase OU>" -SearchScope Subtree
- }
- Else {
- $computers = Get-ADComputer -Filter {Enabled -eq $true} -SearchBase "<SearchBase OU>" -SearchScope Subtree
- }
- ForEach($computer in $computers) {
- $pingTest = Test-Connection -ComputerName $computer.Name -Count 1 -BufferSize 16 -AsJob
- $computer | Add-Member -NotePropertyName "PingJob" -NotePropertyValue $pingTest -Force
- $computer | Add-Member -NotePropertyName "PingReturn" -NotePropertyValue $null -Force
- }
- Get-Job | Wait-Job | Out-Null
- ForEach($computer in $computers){
- If($computer.PingReturn -eq $null){
- $computer.PingReturn = Receive-Job $computer.PingJob
- }
- }
- Get-Job | Remove-Job
- $computers = $computers | Where-Object {$_.PingReturn.StatusCode -eq 0} | Select-Object -Property * -ExcludeProperty PingJob,PingReturn
- $computers
- }
Advertisement
Add Comment
Please, Sign In to add comment