Note that there are some explanatory texts on larger screens.

plurals
  1. PORemove null values from GET-ADUSER
    primarykey
    data
    text
    <p>I have the below query in powershell. If the ManageBy field is null I do not want it to show in the list. How would I accomplish this with my code? thanks</p> <pre><code>Import-Module activedirectory (Get-ADUser -Identity user –Properties MemberOf | Select MemberOf).MemberOf | Get-ADGroup -Properties ManagedBy | Select Name, ManagedBy, Distinguishedname, GroupCategory | Where-Object { $_.Distinguishedname -notlike "*Test*" -and $_.Distinguishedname -notlike "*Test1*" -and $_.name -notlike "*Test3*"}| ForEach-Object { If ($_.ManagedBy) { $result = New-Object PSObject Add-Member -input $result NoteProperty 'Managed By' ((Get-ADUser -Identity $_.ManagedBy).givenName + ' ' + ((Get-ADUser -Identity $_.ManagedBy).surName)) Add-Member -input $result NoteProperty 'Group Name' $_.Name Add-Member -input $result NoteProperty 'Email' (Get-ADUser -Identity $_.ManagedBy -Properties mail).Mail Add-Member -input $result NoteProperty 'Group Type' $_.GroupCategory Write-Output $result } } | select 'Email','Group Name','Managed By','Group Type' | sort 'Managed By' </code></pre> <p><strong>Tried</strong> <code>select 'Email','Group Name','Managed By','Group Type' | where {$_.'Managed By'} | Sort 'Managed By'</code> <strong>and received the below error still.</strong></p> <pre><code>Get-ADUser : Cannot find an object with identity: 'CN=Managers,OU=Groups,OU=Users,OU=New York,DC=company,DC=net' under: 'DC=company,DC=net'. At line:9 char:55 + Add-Member -input $result NoteProperty 'Managed By' ((Get-ADUser -Identity $_.Ma ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (CN=Managers...DC=company,DC=net:ADUser) [Get-ADUser], ADIdentityNotFoundException + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,Microsoft.ActiveDirectory.Management.Commands.GetADUser Get-ADUser : Cannot find an object with identity: 'CN=Managers,OU=Groups,OU=Users,OU=New York,DC=company,DC=net' under: 'DC=company,DC=net'. At line:11 char:49 + Add-Member -input $result NoteProperty 'Email' (Get-ADUser -Identity $_.ManagedB ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (CN=Managers...DC=company,DC=net:ADUser) [Get-ADUser], ADIdentityNotFoundException + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,Microsoft.ActiveDirectory.Management.Commands.GetADUser Email Group Name Managed By Group Type ----- ---------- ---------- ---------- regu.r@company.com FG-SFO-AudioProcessingWorkshop CN=Useron\, Michael,OU=Users,OU=New York,DC=company,DC=net Security DCB@company.com FG-NTHA1-D-Work-Release Managers CN=Useron\, Michael,OU=Users,OU=New York,DC=company,DC=net Security DCB@company.com Engineering, Digital Work Applications CN=Useron\, Michael,OU=Users,OU=New York,DC=company,DC=net Distribution DCB@company.com FG-NTHA1-D-Work-Release Users CN=Useron\, Michael,OU=Users,OU=New York,DC=company,DC=net Security kent@company.com Jupiter-developers CN=Useron\, Michael,OU=Users,OU=New York,DC=company,DC=net Distribution LMAU@company.com IDP Phase 4-5 CN=Useron\, Michael,OU=Users,OU=New York,DC=company,DC=net Security PXM@company.com Eng, Product CN=Useron\, Michael,OU=Users,OU=New York,DC=company,DC=net Security user1@company.com FG-Projects-ENG_Common CN=Useron\, Michael,OU=Users,OU=New York,DC=company,DC=net Security user1@company.com FG-Projects-companyMediaProducer CN=Useron\, Michael,OU=Users,OU=New York,DC=company,DC=net Security SXM@company.com FG-NTHA1-companyMediaProducer CN=Useron\, Michael,OU=Users,OU=New York,DC=company,DC=net Security DCB@company.com FG-NTHA1-D-Work-Stage CN=Useron\, Michael,OU=Users,OU=New York,DC=company,DC=net Security AAQUI@company.com FG-Projects-FunctionalActivityReports-READ CN=Useron\, Michael,OU=Users,OU=New York,DC=company,DC=net Security nelle.chapman@company.com AG-EPSRM_Power_Requestor CN=Useron\, Michael,OU=Users,OU=New York,DC=company,DC=net Security user2@company.com Build Team CN=Useron\, Michael,OU=Users,OU=New York,DC=company,DC=net Distribution user2@company.com Build Notifications CN=Useron\, Michael,OU=Users,OU=New York,DC=company,DC=net Distribution FG-nyo-file-01-projects-buildsarea_ReadWrite CN=Useron\, Michael,OU=Users,OU=New York,DC=company,DC=net Security MMS-Users CN=Useron\, Michael,OU=Users,OU=New York,DC=company,DC=net Distribution holly.krer@company.com Work BG All CN=Useron\, Michael,OU=Users,OU=New York,DC=company,DC=net Distribution test CN=Useron\, Michael,OU=Users,OU=New York,DC=company,DC=net Distribution user2@company.com FG-SFO-File-01-Projects-companyMediaProducerArchive-RW CN=Useron\, Michael,OU=Users,OU=New York,DC=company,DC=net Security user2@company.com AG-EC Commander Users CN=Useron\, Michael,OU=Users,OU=New York,DC=company,DC=net Security EJN@company.com FG-Projects-CP750 CN=Useron\, Michael,OU=Users,OU=New York,DC=company,DC=net Security kent@company.com Jupiter-buildmasters CN=Useron\, Michael,OU=Users,OU=New York,DC=company,DC=net Distribution </code></pre> <p>The results are above</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload