Created
June 13, 2016 15:51
-
-
Save randomchance/0a5958d7d07fcb3f3931c280bb09b99d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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