Get-RemoteMailbox returns >>

I think I’m missing something obvious here.

We’re using Office 365, Exchange 2010 on-premises.

I need to get all students who are marked as hidden from the address list and then unhide them.

I think this:

Get-RemoteMailbox -ResultSize Unlimited | Where {$_.OnPremisesOrganizationalUnit -eq “OU=Students,OU=MyCollege,DC=Mydomain,DC=edu”

should show me all students, and then I’d do an:

-AND Where {$_.HiddenFromAddressListsEnabled -eq $True} |

and then finally whatever is the command to unhide (using Set-RemoteMailbox, of course).

But, the first one just returns “>>”, which I think means it wants something. But what? Get-RemoteMailbox without the Where returns all sorts of stuff.

The double prompt means you’ve left something open - likely unmatched quotes or curly braces. PowerShell is indicating that it wants you to “finish” before running what you’ve typed.

I suspect it’s because you’re mis-using Where-Object, but it’d be more helpful to see the entire command you’re trying to run. I don’t want to assume anything based on the way you typed it above.

Putting the code together from your post, it looks like this.

Get-RemoteMailbox -ResultSize Unlimited | Where {$_.OnPremisesOrganizationalUnit -eq "OU=Students,OU=MyCollege,DC=Mydomain,DC=edu"-AND Where {$_.HiddenFromAddressListsEnabled -eq $True}

If that is what you actually have, then your problem is that you are putting where in again when you don’t need to. Which is causing and unterminated code block. Remove the extra “Where {” and you should be good.

Get-RemoteMailbox -ResultSize Unlimited | Where-Object {$_.OnPremisesOrganizationalUnit -eq "OU=Students,OU=MyCollege,DC=Mydomain,DC=edu"-AND $_.HiddenFromAddressListsEnabled -eq $True}

So, actually, if you’re typing it EXACTLY as above, that’s your problem. But it isn’t a problem per se. You’ve left the closing curly brace off the first line, which is causing the continuation prompt.

You’d then simply type:

-and $_.hiddenfromaddresslistsenabled }

And press Enter twice.

Notice two things. First, I don’t re-use Where-Object. Second, I don’t need to compare the property to $True, because it’s already true or false. So, both sides of my Boolean comparison live within a single set of curly braces being fed to a single Where-Object command.

Make sense?

Don and Curtis, thanks very much. A missing brace was indeed the problem (like I said, something obvious!)

And I didn’t realize the Where could apply to two conditions at once. That’s neat!

So now I do:
Get-RemoteMailbox -ResultSize Unlimited | Where {$_.OnPremisesOrganizationalUnit -eq “OU=Students,OU=My College,DC=mydomain,DC=edu”}

And it runs, but returns…no results. There is indeed a space in “My College”, but it’s already in quotes so I wouldn’t think that would matter. Spelling is correct and the order is correct (it goes up the AD tree, right? So the first OU is the one the accounts are actually inside, and so on up the tree).

Your problem is that the OnPremisesOrganizationalUnit property does not contain the OU in that format.

You can confirm this by just looking at the value from one of your RemoteMailBoxes

Get-RemoteMailbox -Identity user@my.domain | select OnPremisesOrganizationalUnit

Results in something like

You’re a scholar and a gentleman, Curtis! That did the trick, and I was able to unhide them all.