Query OnPremise AD for Specific AD attributes not working?

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
ITEngineer
Posts: 138
Joined: Wed Oct 12, 2011 10:52 am

Query OnPremise AD for Specific AD attributes not working?

Post by ITEngineer » Mon Feb 18, 2019 2:59 pm

Hi People,

I need some help to modify the below script to show additional column Office 365 or OnPremise:

Code: Select all

Get-ADGroup -Filter {Name -like '*IT*'} | Select-Object @{ n='Group'; e={ $_.Name } }, @{ n='Members'; e={ (Get-ADGroup $_.DistinguishedName -Properties Members | Select-Object Members).Members } } |
    Get-ADGroupMember -Recursive |
        Get-ADUser -Properties Mail | Select-Object Name, sAMAccountName, Mail |
            Export-CSV -path "C:\RESULT\Group_members.csv" -NoTypeInformation
The above simple PowerShell script is only working to export the list of the users in a particular member of AD Groups.

I also have tried the below script to query OnPremise AD with the specific attributes, but still failed no result returned?

Code: Select all

Get-ADUser -Filter * -Properties msExchRemoteRecipientType, msExchRecipientDisplayType, msExchRecipientTypeDetails, targetAddress | 
    Where-Object {($_.msExchRemoteRecipientType -eq 4) -and 
        ($_.msExchRecipientDisplayType = '-2147483642') -and
        ($_.msExchRecipientTypeDetails = '2147483648') -and
        ($_.targetAddress -contains "*.onmicrosoft.com*")
    }


But it returns some error:
msExchRecipientDisplayType : The term 'msExchRecipientDisplayType' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,
verify that the path is correct and try again.
At line:3 char:10
+ (msExchRecipientDisplayType = '-2147483642') -and
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (msExchRecipientDisplayType:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Any help would be greatly appreciated.

Thanks,
/* IT Engineer */

User avatar
jvierra
Posts: 13507
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Query OnPremise AD for Specific AD attributes not working?

Post by jvierra » Mon Feb 18, 2019 4:50 pm

You are using "=" and should be using "-eq".

Locked