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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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:
But if I run the Get-WmiObject Win32_UserProfile command just by itself, I can see the profile there.
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
But if I run the Get-WmiObject Win32_UserProfile command just by itself, I can see the profile there.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER
Part of my code worked.
get-qadcomputer computername | foreach {$servername=$_.name
$test = test-path \\$servername\c$\users\USE
"$servername, $test$" >> c:\localprofile.txt
}