Recently had to get a list of users within active directory that were pointing at a specific file servers.
Came up with the following PowerShell, searching a specific domain and then looks for servers
Note:
- The \">\">\\*<servername>\*, is because I found that the command had a issue with certain servernames if I just put \">\">\\<servername>\*. I spent a little time looking at this but couldnot find a reason and by slipping in \\* just made it work consistently.
-SearchBase "DC=<domain>,DC=local"
with your domain… i.e. if your fqdn is company.local then this would read
-SearchBase "DC=company,DC=local"
- Also replace <servernameX> with your server names with your domain… i.e. if your fqdn is company.local then this would read
Get-ADUser -Filter {(homedirectory -like '\\*<servername1>\*' -or homedirectory -like '\\*<servername2>\*') -and (Enabled -eq "True")} -SearchBase "DC=<domain>,DC=local" -Properties homedirectory | Select-Object name, enabled, homedirectory
No comments:
Post a Comment