Advertisement
Journeym

check.if.file.exists.on.workstations

Jan 10th, 2017
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #change "Searchbase "OU=SOMEOU,DC=DC,DC=CONTOSO,DC=COM"" to your desired OU / Domain
  2. Get-ADComputer -Filter {operatingSystem -like "*Windows*7*" -or operatingSystem -like "*Windows*8.1*"} -Searchbase "OU=SOMEOU,DC=DC,DC=CONTOSO,DC=COM" -Properties operatingSystem,description,lastLogon|
  3. sort DNSHostName|
  4. foreach {
  5. $path="\\$($_.DNSHostName)\c$\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.ActiveDirectory.Management" #change this string to set searched file location
  6. if ($(Test-Connection -ComputerName $_.DNSHostName -ErrorAction SilentlyContinue -Count 1).StatusCode -eq 0)
  7. {
  8. $test=Test-Path $path
  9. }
  10. else
  11. {
  12. $test = 'Offline'
  13. }
  14. If ($test -eq $true)
  15. {
  16. #Write-Host "$($test)   " -ForegroundColor Green -NoNewline               #uncomment these two lines to
  17. #Write-Host " $($_.DNSHostName) $($_.Description) $($path)"               #get also successes in a log
  18. }
  19. else
  20. {
  21. if ($test -eq $false)
  22. {
  23. Write-Host "$($test)  " -ForegroundColor Red -NoNewline
  24. Write-Host " $($_.DNSHostName) $($_.Description) $($path)"
  25. }
  26. else
  27. {
  28. Write-Host $test -ForegroundColor Yellow -NoNewline
  29. Write-Host " ($(((Get-Date) - ([DateTime]::FromFileTime($_.lastLogon))).Days)) Days" -ForegroundColor Yellow -NoNewline
  30. Write-Host " $($_.DNSHostName) $($_.Description) $($path)"
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement