Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

3 Answers 3

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
add comment

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($_.properties.profilepath[0] -notmatch '^\\\\servername\\sharename\\')
        $op = '' | select name,profilepath
        $op.name = $_.properties.name[0]
        $op.profilepath = $_.properties.profilepath[0]
} | export-csv -NoTypeInformation c:\path\to\save.csv
share|improve this answer
add comment

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
add comment

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.