A simple PowerShell query command for AD

Source: Internet
Author: User

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.


    1. All Sydney users can use-searchbase to limit the scope of the Search OU;

    2. 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* '}

    1. Various properties that need to be viewed can be listed with-properties

    2. 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 '/'

    3. You can customize the output table header by {name= "xxx" '; express={xxx}} ' format

    4. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.