Query OnPremise AD for Specific AD attributes not working?

Ask your 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.
This topic is 5 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
ITEngineer
Posts: 216
Last visit: Thu Mar 23, 2023 5:45 pm
Has voted: 4 times

Query OnPremise AD for Specific AD attributes not working?

Post by ITEngineer »

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 */
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

You are using "=" and should be using "-eq".
This topic is 5 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked