Find User Profiles on Domain Computers

By | 2017-12-17

This script does nothing more than search a list of computers for a specified user profile.

The script pulls a list of computer objects from Active Directory, and searches the c:\users directory on each computer for a directory name that matches the specified user name. If a matching directory name is found, then the UNC path (which includes the remote computer name) is written to the screen.

Param(
 [Parameter(Mandatory=$True,Position=1)]
 [String]$UserToSearchFor
)
$ADFilter="*"
$ADSearchBase="OU=computers,DC=mydomain,DC=com"
$ComputerList=Get-ADComputer -filter $ADFilter -SearchBase "$ADSearchBase" -SearchScope Subtree
$NumberOfComputers=$ComputerList.Count
$CurrentHostNumber=1
ForEach($Computer in $ComputerList){
 $PathToTest="\\" + $Computer.Name + "\c$\users\$UserToSearchFor*"
 write-progress -activity "Checking remote hosts for $UserToSearchFor" -status $Computer.Name -percentcomplete (($CurrentHostNumber/$NumberOfComputers)*100)
 if((Test-path -path $PathToTest) -eq $True)
 {
  write-host $PathToTest
 }
 $CurrentHostNumber++
}
write-host "`nSearch Complete.`n"

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.