Hi Everyone,
Trying to use the filter parameter on Get-CASMailbox and running into an issue. The original thought was to do this:
<pre class=“lang:ps decode:true”>Get-CASMailbox -ResultSize Unlimited -filter {hasactivesyncdevicepartnership -eq $true -and whencreated -gt “05/30/2013”} | select displayname,whencreated
Works great. Want to make the date a variable? Can’t get it to work. I’ve tried datetime variable, I’ve converted it to string using .ToString(“MM/dd/yyyy”) with no luck.
I’ve also attempted to assign the scriptblock to a variable (even tried an hashtable) but still no luck. Here’s the test code at this time:
<pre class="lang:ps decode:true ">cls
$dt = ((Get-Date).AddDays(-5)).ToString(“MM/dd/yyyy”)
$filter = {hasactivesyncdevicepartnership -eq $true -and whencreated -gt $dt}
#$filter = {$(filter)}
Write-Host “`$DT = $dt”
Write-Host $filter
Get-CASMailbox -ResultSize Unlimited -filter $filter | select displayname,whencreated
Write-Host “`$DT = $dt”
I’ve attempted to put the $DT in double and single quotes, and a few other methods. The result seems to be $null no matter what I do (so I’m either getting ALL mailboxes which if you use the manual command and say WhenCreated -eq $null happens) or I get an error (usually unable to convert to datetime variable).
The weird thing is if I run it from PowerGUI the code works fine, it’s only when I run it from the shell that I have the problem.
Of course, I could solve this by simply piping into Where and be done with it but the performance hit is significant. With my little 200 person network using the manual filter parameter the query took about half a second. With the Where clause it took 6.5 seconds! Larger deployments this would get significantly longer!
So, any thoughts?
*I have tried a lot of different things, so if I forgot to mention something here, sorry… I’m trying to keep it concise and not write a novel!Â