Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

PowerShell Weird .Count Behaviour!

$
0
0

Hello,

I'm getting weired random results from PowerShell. Here is the code:

$UserName = "Test.Test10"
$MatchingUsers = Get-Recipient -ANR "$UserName" | Where-Object {($_.RecipientType -eq "UserMailbox")}
$MatchingUsers.Count

When I execute the above code in Exchange Management Console, it sometimes works and sometimes not. i.e., The user named "Test.Test10" exists in Active Directory, but not contain mailbox. So it should result "0" for $MatchingUsers.Count.

I tried to log-in all several Mailbox servers directly and the cleared all sessions and even rebooted couple of lab servers. Still the result is same!

I'm not sure whether this a bug in Exchange side or in PowerShell or my code is incorrect! Any suggestions/help would be greatly appreciated. Thanks!

It works sometimes:

It won't sometimes:



Viewing all articles
Browse latest Browse all 2562

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>