Reputation: 114
I have a list of office 365 groups. I want to check if they are hidden from Global Address List. For some reason when I run foreach loop there is no output at all. Could you, please point out what I am doing wrong.
Here's how I connected to Exchange:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
This is what I've tried to do:
#get list of o365 groups
$teams = Get-UnifiedGroup |Where-Object {$_.WelcomeMessageEnabled -like "False"}|select -ExpandProperty Alias
#check $teams type just to be on the safe side
$teams.gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
#check content of $teams variable
$teams
AllEMEA
AmericasApps
AmericasAR
AmericasConnectivity
AnalystTeam
APACExtendedServices
APACGatewayMigration
APACMarketGateways
APACProfessionalServices
APACSales
When I manually check groups one by one, it works just fine.
Get-UnifiedGroup -Filter {Alias -eq "AllEMEA"} | select DisplayName,hiddenfromaddresslistsenabled
DisplayName HiddenFromAddressListsEnabled
----------- -----------------------------
All EMEA False
But when i pipe $teams to foreach loop it hangs for a moment like it processes the array but then, there is no output at all.
>$teams | %{Get-UnifiedGroup -Filter {Alias -eq $_}} | select DisplayName,hiddenfromaddresslistsenabled
>
#I've tried this approach (which is as far as i know the same), but result is the same
>foreach ($team in $teams) {Get-UnifiedGroup -Filter {Alias -eq "$team"}} | select DisplayName,hiddenfromaddresslistsenabled
>
I want to see a list of groups and their hiddenfromaddresslistsenabled property. Any help appreciated.
Upvotes: 0
Views: 3461
Reputation: 114
The problem here is -Filter
parameter does not accept pipeline input.
Filter <string>
Required? true
Position? Named
Accept pipeline input? false
Parameter set name Filter
Aliases None
Dynamic? true
I see the same behavior with Get-aduser -Filter
,for example, so the workaround here is to not use -Filter
but use -Identity
parameter which accepts pipeline input.
The @Nevenka's answer works as well, but I wanted to post the root cause for this problem, if anyone will encounter the same problem.
Upvotes: 0
Reputation: 11
Can you check the following code below?
$teams = Get-UnifiedGroup | Where {($_.HiddenFromAddressListsEnabled -eq $True) -and ($_.WelcomeMessageEnabled -like $false)} | ft Name, Alias, HiddenFromAddressListsEnabled, WelcomeMessageEnabled
$teams.gettype() <# if you need to check the type #>
$teams
Upvotes: 1