Query AD from file generated by user home directories stored on file server

New powershell script. Goes to user home directory on remote server and dumps the folder names to a file. Then, goes through each line in that file and queries AD to make sure the user still exists and outputs it to the console. Not finished yet. Previous admins weren’t keeping up with deleting the home diretories as users left the company. Now I have to be able to add the list of file servers with home directories. meh!

Clear-Host

Get-ChildItem -path \\server\path | select-object name | Out-File c:\usernames.txt

$sname = (Get-Content c:\usernames.txt) -replace ‘ {2,}’,'’

Foreach ($name in $sname)
{
$result = Get-QADUser -SamAccountName $name -ov outvar | Out-Null
if ($outvar -ne $null)
{}
else
{Write-Host $name}
}Edit

1 Response to “Query AD from file generated by user home directories stored on file server”


  1. 1 Alexander7 Trackback on Jul 17th, 2011 at 1:41 pm

Leave a Reply

You must login to post a comment.