Zenoxio
Zenoxio

Reputation: 1

Select ManagedBy under OU in Powershell?

I have this Powershell code

$offices = get-qadobject -Type 'organizationalUnit' -SearchRoot 'ou=Test_OU,dc=domain,dc=org'
Foreach($office in $offices)
{
    $line = $office | select Name,Description,ManagedBy
    $line
}

It is grabbing everything except for ManagedBy which ends up blank. How do I get the email and name of the ManagedBy object? The AD object contains this data.

Note there's some Quest (https://jschofield22.wordpress.com/tag/get-qadobject/) use in here, but it's similar to Get-ADObject.

Upvotes: 0

Views: 235

Answers (1)

Bill_Stewart
Bill_Stewart

Reputation: 24585

How about something like:

Get-ADOrganizationalUnit -Filter * -SearchBase "OU=Base,DC=fabrikam,DC=com" -Properties Description |
  Select-Object DistinguishedName,
    Name,
    Description,
    ManagedBy,
    @{Name="ManagedBy_mail"; Expression={(Get-ADObject $_.ManagedBy -Properties mail).mail}}

Upvotes: 1

Related Questions