Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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.

share|improve this answer

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=*))'
$a.pagesize = 1000

$a.findall() | foreach-object {
    if($[0] -notmatch '^\\\\servername\\sharename\\')
        $op = '' | select name,profilepath
        $ = $[0]
        $op.profilepath = $[0]
} | export-csv -NoTypeInformation c:\path\to\save.csv
share|improve this answer

It's more efficient if you make the not match condition part of the LDAP query

$a = [adsisearcher]'(&(objectclass=user)(objectcategory=user)(!profilepath=\\\\servername\sharename*))'
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.