Several methods of Powershell Get Domain user

Source: Internet
Author: User

One, get-user single user query

$User

Second, Get-user Multi-user circular query

$export[Email protected]()$Users=get-aduser-Filter*-searchscope Subtree-searchbase"ou=xx,ou=xx,dc=xx,dc=xx,dc=xx"-properties *foreach($user inch $users) {#$User =get-aduser-identity wendy-properties *    $name=$user. Name#You can add multiple classes of properties here    $info=new-Object PsObject$info| Add-member-membertype noteproperty-name name-value$name    $export+=$info}$CurrentDate= get-Date$CurrentDate=$CurrentDate. ToString (' yyyy-mm-DD ')$export| Export-csv D:\ps\userPermissioninfo_$CurrentDate. csv-encoding Utf8-notypeinformation
View Code

Third, OU query

Functions code, refer to the Code of http:// www.JSchofield22.wordpress.com

functionget-ouwithobjects{<#. SynopsisFunctionTo get all OUs that contain Users, Groups, or Contacts. DescriptionThisfunctionrequires Quest activeroles AD Management to be installed. The purpose of Thisscript are to go off and find any and all organizationalunits which contain Users, Groups, orcontacts. It performs a count on each of the type of object and prints them to a CSV File. This Isa useful tool forAny Admin getting perform a Active Directory migrationinchOrderto better understand the existing environment. This script does not require and specialprivelagesinchorder to run as your ' re only reading from Active Directory. PARAMETER Domainsthis allows you to input as many domains as you ' d like to scan against. (ex.-domains"domain1","domain2","domain3" ) . PARAMETER outfilethis Specifies the directory path and file name forThe CSV output. (ex.-Outfile c:\temp.csv). Notesname:get-OUWithObjects.ps1Author:Josh schofielddatecreated:12/28/2012 . LINK http://www.JSchofield22.wordpress.com. Exampleget-ouwithobjects-domains"Domain1","Domain2"-outfile"C:\temp\test.csv" #> param([Parameter (Mandatory=$true)]$Domains, [Parameter (Mandatory=$true)][string]$OutFile ) if((get-pssnapin-registered| where {$_. Name-eq "quest.activeroles.admanagement"})-eq $null) {Write-error"Quest.ActiveRoles.ADManagement not installed"} Else{Get-pssnapin-registered| where {$_. Name-eq "quest.activeroles.admanagement"} | Add-pssnapin | out-Nullif((Test-path$OutFile)-eq "True") {del$OutFile} $output= @() foreach($domain inch $domains) {Connect-qadservice$domainGet-qadobject-type"organizationalunit"-includedproperties Name,type,parentcontainer,dn-sizelimit 0| %{ $ouname=$_. Name$parentcontainer=$_. Parentcontainer$adobjects= Get-qadobject-searchroot$_. Dn-searchscope onelevel-includedproperties Type,name-sizelimit 0 | where {($_. type-eq " Contact")-or($_. type-eq "User")-or($_. type-eq "Group"))}$users=$adobjects| where {$_. type-eq "User"}$groups=$adobjects| where {$_. type-eq "Group"}$contacts=$adobjects| where {$_. type-eq " Contact"} $results=""|Select Domain, Name, UserCount, GroupCount, Contactcount, Parentcontainer$results. Domain =$domain$results. Name =$ouname$results. Parentcontainer =$parentcontainer if($users -ne $null) { $results. UserCount =$users. Count}#End of User Check if($groups -ne $null) { $results. GroupCount =$groups. Count}#End of User Check if($contacts -ne $null) { $results. Contactcount =$contacts. Count}#End of User Check $output+=$resultsClear-variable$results-erroraction silentlycontinueclear-variable$ouname-erroraction silentlycontinueclear-variable$parentcontainer-erroraction silentlycontinue$adobjects=$null$users=$null$groups=$null$contacts=$null } #End of Get qadobject OU } $output| Export-csv$OutFile-Notypeinformation}}
View Code

Several methods of Powershell Get Domain user

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.