Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #change "Searchbase "OU=SOMEOU,DC=DC,DC=CONTOSO,DC=COM"" to your desired OU / Domain
- 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|
- sort DNSHostName|
- foreach {
- $path="\\$($_.DNSHostName)\c$\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.ActiveDirectory.Management" #change this string to set searched file location
- if ($(Test-Connection -ComputerName $_.DNSHostName -ErrorAction SilentlyContinue -Count 1).StatusCode -eq 0)
- {
- $test=Test-Path $path
- }
- else
- {
- $test = 'Offline'
- }
- If ($test -eq $true)
- {
- #Write-Host "$($test) " -ForegroundColor Green -NoNewline #uncomment these two lines to
- #Write-Host " $($_.DNSHostName) $($_.Description) $($path)" #get also successes in a log
- }
- else
- {
- if ($test -eq $false)
- {
- Write-Host "$($test) " -ForegroundColor Red -NoNewline
- Write-Host " $($_.DNSHostName) $($_.Description) $($path)"
- }
- else
- {
- Write-Host $test -ForegroundColor Yellow -NoNewline
- Write-Host " ($(((Get-Date) - ([DateTime]::FromFileTime($_.lastLogon))).Days)) Days" -ForegroundColor Yellow -NoNewline
- Write-Host " $($_.DNSHostName) $($_.Description) $($path)"
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement