Last active
December 12, 2015 01:38
-
-
Save ddhahn/4692261 to your computer and use it in GitHub Desktop.
Is it in AD? Takes a list of machine names from a file and sees if there is an computer object by that name in AD.. If not, writes the name of the computer to a file
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
$machines = Get-Content "c:\temp\machines.txt" | |
del c:\temp\not-in-ad.txt | |
foreach ($machine in $machines) { | |
#query AD to see if this machine exists. If not, write to a file | |
#uses the quest AD cmdlets..Probably need to change to built in AD cmdlets in POSH 2.0 | |
$this = Get-QADComputer -Identity "contoso\$machine$" -ErrorVariable $Error_get_computer | |
if ($this -ne $null){ | |
Write-Host "$machine is in AD" | |
} | |
else { | |
Write-Host "$machine is NOT in AD" | |
Out-File -InputObject "$machine" -Append -FilePath "c:\temp\not-in-ad.txt" -Encoding ASCII} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment