# How to use powershell to check the location of user profile locations on the server?

Is it possible to find all the users profiles that are not on a certain server/folder using powershell and regular expressions? If so how would one go about this?

-

In powershell, use the Win32_UserProfile WMI Object to find profiles remotely:

gwmi -ComputerName <computername> Win32_UserProfile


To find user profiles not on a server (or that are, either way), you could do something like:

gwmi -ComputerName <computername> Win32_UserProfile | ? {"C:\Users\<username>" -contains $_.LocalPath}  If the path exists, it will give results if not then it won't. You can do fancier stuff than this, but basically this should accomplish what you need without using regular expressions. - Funny, I just had to do this today. Try this script, replacing servername, sharename, and c:\path\to\save.csv with appropriate values. I typed this from memory, so I can't promise no bugs :( $a = [adsisearcher]'(&(objectclass=user)(objectcategory=user)(profilepath=*))'
[void]$a.propertiestoload.add('name') [void]$a.propertiestoload.add('profilepath')
$a.pagesize = 1000$a.findall() | foreach-object {
if($_.properties.profilepath[0] -notmatch '^\\\\servername\\sharename\\') {$op = '' | select name,profilepath
$op.name =$_.properties.name[0]
$op.profilepath =$_.properties.profilepath[0]
$op } } | export-csv -NoTypeInformation c:\path\to\save.csv  - It's more efficient if you make the not match condition part of the LDAP query Try: $a = [adsisearcher]'(&(objectclass=user)(objectcategory=user)(!profilepath=\\\\servername\sharename*))'

-