Domanda

I have two near-identical Powershell scripts.

http://poshcode.org/4112

http://poshcode.org/4113

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.

È stato utile?

Soluzione 2

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.

Altri suggerimenti

What's the type of $size when you encounter those errors? Print all mailboxes with their size to get a better view of those objects. In any case, If I may suggest a solution:

$totalSize = Get-Mailbox -Filter {WindowsEmailAddress -like "*$uucenter*"} | 
Get-MailboxStatistics | Foreach-Object {$_.TotalItemSize.Value} | 
Measure-Object -Sum | Foreach-Object {$_.Sum}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top