Today boss let me output a simple report, need to list all the users in Sydney except the system account, including their name, phone, landline, the OU, company and so on information.
This basic command is very simple, get-aduser can be achieved, a few filter conditions a little thought about a bit.
All Sydney users can use-searchbase to limit the scope of the Search OU;
Exclude the System account, because all the system accounts are located under the same OU, then filter out the OU when searching, for example
Get-aduser-filter * | Where-object{$_.disginuishedname-notlike ' *xxxx* '}
Various properties that need to be viewed can be listed with-properties
The OU itself is not a property, but it can list the user's Caonicalname properties, such as the format of/domain/ouname/username, and then handle it through the split delimiter '/'
You can customize the output table header by {name= "xxx" '; express={xxx}} ' format
Last exported to CSV file save
Get-aduser-filter *-searchbase "Ou=sydney,dc=omnicom,dc=com,dc=au"-properties Name,mobile,title,ipphone, Canonicalname,company,office |? {$_.distinguishedname-notlike ' *sydney non-replication* '}| Select Name, Title, mobile,@{name= "Extension"; expression={$_.ipphone}},@{name= "OU"; expression={$temp = ($_. Canonicalname-split '/'); $temp [$temp. count-2]}}, company, office | Sort name| Export-csv C:\temp\users.csv
This article is from the "Mapo Tofu" blog, please be sure to keep this source http://beanxyz.blog.51cto.com/5570417/1675600
A simple PowerShell query command for AD