Skip to content

Instantly share code, notes, and snippets.

@randomchance
Created June 13, 2016 15:51
Show Gist options
  • Save randomchance/0a5958d7d07fcb3f3931c280bb09b99d to your computer and use it in GitHub Desktop.
Save randomchance/0a5958d7d07fcb3f3931c280bb09b99d to your computer and use it in GitHub Desktop.
$Computers = (Get-ADComputer -Filter {Name -like '*'}).DNSHostName
$TestedPath = "C:\Program Files\Git" # this is the example path I am checking for.
if(-not $Credential ){
$Credential = Get-Credential
}
Write-Verbose "Determining which computers can be reached, this may take a long time depending on your environment." -Verbose
[string[]] $reachableComputers = $Computers | where {Test-Connection -ComputerName $_ -Quiet -Count 1}
Write-Verbose "Done. Testing all$($reachableComputers.count) computers..." -Verbose
$job = Invoke-Command -ComputerName $reachableComputers -Credential $Credential -ScriptBlock {
[pscustomobject]@{
PathLocated = (Test-Path -Path $using:TestedPath)
}
# This is returning an object instead of just a boolean,
# because then invoke-command automagically attaches the computername
} -AsJob -ErrorAction SilentlyContinue
$results = $job | Receive-Job
$results | Format-Table -AutoSize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment