Page 1 of 1

Query OnPremise AD for Specific AD attributes not working?

Posted: Mon Feb 18, 2019 2:59 pm
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,

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

Posted: Mon Feb 18, 2019 4:50 pm
by jvierra
You are using "=" and should be using "-eq".