MrClayGiovanni
MrClayGiovanni

Reputation: 27

narrowing OU to only return users from all results

so I currently have code that returns the ADUsers of a company. I want to narrow the results that it brings back to only show the users and not the other results that its returning.

I have the following code

Import-Module ActiveDirectory

$fmtADUser = 

      @{Expression={$_.Name};Label="Name";Width=25},
      @{Expression={$_.UserPrincipalName};Label="User Principal Name";Width=30},
      @{Expression={$_.Created};Label="Created On";Width=30},
      @{Expression={$_.lastLogonDate};Label="Last Logged On Date";Width=30}

$host.UI.RawUI.BufferSize = New-Object System.Management.Automation.Host.Size(160,5000)

Get-ADUser -Filter *  -Properties * | Format-Table -Property $fmtADUser

Upvotes: 1

Views: 38

Answers (1)

vamshib69
vamshib69

Reputation: 11

If you are just trying to pull the Names/users you can try

Get-ADUser -Filter 'Name -like "*"' | Format-Table Name -A

or

comment out/remove the other lines apart from Name label as follows from the hashtable.

Import-Module ActiveDirectory
    $fmtADUser = 
  @{Expression={$_.Name};Label="Name";Width=25}
  #@{Expression={$_.UserPrincipalName};Label="User Principal Name";Width=30},
  #@{Expression={$_.Created};Label="Created On";Width=30},
  #@{Expression={$_.lastLogonDate};Label="Last Logged On Date";Width=30}

$host.UI.RawUI.BufferSize = New-Object System.Management.Automation.Host.Size(160,5000)

Get-ADUser -Filter *  -Properties * | Format-Table -Property $fmtADUser

Both will have the same results but the upper one will be little faster as per my test on my local.

Upvotes: 1

Related Questions