I have two near-identical Powershell scripts.
The only difference between the two is 2 places where uu-lillebaelt has been changed to uuoresund. When I run the script with -like 'uuoresund', I get a bunch of errors saying: You cannot call a method on a null-valued expression And this is happening when calling:
$size.IndexOf
$size.Substring
I have made sure, that size is not actually null, so that is not the problem. I feel that it must be something about the -like operator I do not understand.
I found the problem. The Get-Mailbox on the domain also returned a DiscoverySearchMailbox that must be empty, or atleast return something that is not in a format. So to fix that, I just added a -notlike to get rid of that :)
Well, good thing it happened, otherwise I probably wouldn't have caught it.