Find User Profiles on Domain Computers

Posted On 2017-12-17 by dwirch
Keywords:
Tags: Powershell Scripting Windows
Views: 78


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"

Requirements

Requires the Active Directory PowerShell module be loaded in the current session.


About the Author

dwirch has posted a total of 188 articles.


Comments On This Post

No comments on this post yet!


Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.


Your IP address is:54.82.57.154

Before you can post, you need to prove you are human. If you log in, this test goes away.




Code Links