Search Tools Links Login

Find User Profiles on Domain Computers


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"

About this post

Posted: 2017-12-17
By: dwirch
Viewed: 777 times

Categories

Scripting

Powershell

Windows

PowerShell Code Cache

Attachments

No attachments for this post

Requirements

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


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.