Link to home
Start Free TrialLog in
Avatar of sedberg1
sedberg1

asked on

Script to check if a user has a profile on a server

We have 200+ Windows 2008 and 2008 R2 servers and about 150 tech support personnel who can log into the server.  Our tech support personnel roster has a high turnover, so when someone leaves the company, we have the possibility of checking these 200+ servers for local profiles of the tech support personnel and then deleting them.

Since this is a ridiculously tedious process, we want to script this somehow.  All the servers belong to one domain, so I'm thinking checking AD for a server list and then running this server list against the username of the tech support guy who left.  And then we could potentially script the deletion of the profile or go in manually (script is preferrable).

Please don't tell me to use roaming profiles or folder redirection as my solution.  That is in the process but due to the complexity of our environment is not an easy deployment.  Any suggestions?
Avatar of Joseph Daly
Joseph Daly
Flag of United States of America image

Here is a quick and dirty script that will do this for you. Basically I have a single computer name in there but you can modify the get-qadcomputer part to use an LDAP filter, OSversion, etc to pull computers from AD.

get-qadcomputer computername | foreach {$servername=$_.name
$test = test-path \\$servername\c$\users\USERNAME
"$servername, $test$" >> c:\localprofile.txt
}
ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sedberg1
sedberg1

ASKER

@footech, thanks for the script.

I do have a list of computernames already but am trying it out with just 1 computername in the text file right now.  When I run the script, this is what I get:

Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At C:\users\mram\Desktop\profile2.ps1:9 char:31
+   $userprofile = Get-WmiObject <<<<  Win32_UserProfile -computername $computer -filter "SID = '$userSID'"
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

Open in new window


But if I run the Get-WmiObject Win32_UserProfile command just by itself, I can see the profile there.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Odd that that part didn't work for you, I've never encountered any issues with it.  But I'm glad you found another way that would work for you.
Part of my code worked.