uwsppm
asked on
Create a dynamic distribution group using get-date on whencreated
I set a DDG filter using this Powershell command and it works fine:
Set-DynamicDistributionGro up $ddg2 -RecipientFilter {(whenCreated -ge '9/29/10') -and ((customattribute2 -like '*CLS*') -or (customattribute2 -like '*FA*') -or (customattribute2 -like '*AS*')) -and (alias -ne $null)}
But what I really want is a rolling whencreated Date to only include the accounts crated within the last year from the current date:
Set-DynamicDistributionGro up $ddg2 -RecipientFilter {(whenCreated -ge (get-date).addDay(-365d)) -and ((customattribute2 -like '*CLS*') -or (customattribute2 -like '*FA*') -or (customattribute2 -like '*AS*')) -and (alias -ne $null)}
I don't find anyway of getting the RecipientFilter to accept the get-date command.
Set-DynamicDistributionGro
But what I really want is a rolling whencreated Date to only include the accounts crated within the last year from the current date:
Set-DynamicDistributionGro
I don't find anyway of getting the RecipientFilter to accept the get-date command.
ASKER
Yeah - I realized i missed typing the "s" in the AddDays - but it's the get-date that's the problem as far as I can tell - it doesn't seem acceptable in a DDG filter.
Set-DynamicDistributionGro up : Cannot bind parameter 'RecipientFilter' to the target. Exception setting "RecipientFilter": "Invalid filter syntax. For a description of the filte
r parameter syntax see the command help.
"(whenCreated -ge ((get-date).adddays(-365)) ) -and ((customattribute2 -like '*CLS*') -or (customattribute2 -like '*FA*') -or (customattribute2 -like '*AS*')) -and (alias -ne $nu
ll)" at position 18."
At line:1 char:52
The syntax itself isn't a problem as it works fine with get-user:
Get-User -ResultSize unlimited | where {($_.whenCreated -ge ((get-date).adddays(-365)) )}
Set-DynamicDistributionGro
r parameter syntax see the command help.
"(whenCreated -ge ((get-date).adddays(-365))
ll)" at position 18."
At line:1 char:52
The syntax itself isn't a problem as it works fine with get-user:
Get-User -ResultSize unlimited | where {($_.whenCreated -ge ((get-date).adddays(-365))
OK, well get-date returns a date object, so maybe turn it into a string, by putting single quotes around it, as that has worked in the first example where you specified the date in quotes.
We could also try using ToString(), but I think that's implicitly done anyway by ToShortDateString().
Regards,
Rob.
Set-DynamicDistributionGroup $ddg2 -RecipientFilter {(whenCreated -ge '$(((get-date).adddays(-365)).ToShortDateString())' -and ((customattribute2 -like '*CLS*') -or (customattribute2 -like '*FA*') -or (customattribute2 -like '*AS*')) -and (alias -ne $null)}
We could also try using ToString(), but I think that's implicitly done anyway by ToShortDateString().
Set-DynamicDistributionGroup $ddg2 -RecipientFilter {(whenCreated -ge '$(((get-date).adddays(-365)).ToShortDateString().ToString())' -and ((customattribute2 -like '*CLS*') -or (customattribute2 -like '*FA*') -or (customattribute2 -like '*AS*')) -and (alias -ne $null)}
Regards,
Rob.
P.S. Note that when using any dot notation inside a string, you need to change
((get-date).adddays(-365)) .ToShortDa teString()
to
$(((get-date).adddays(-365 )).ToShort DateString ())
so that the entire formula, with its dot notation, it evaluated as an expression.
Rob.
((get-date).adddays(-365))
to
$(((get-date).adddays(-365
so that the entire formula, with its dot notation, it evaluated as an expression.
Rob.
ASKER
Using the ToShortDateString in quotes results in this error:
Set-DynamicDistributionGro up : Cannot bind parameter 'RecipientFilter' to the target. Exception setting "RecipientFilter": "The value "$(((get-date).adddays(
-365)).ToShortDateString() .ToString( ))" could not be converted to type System.Nullable`1[System.D ateTime]."
I tried removing the ToStirng() and it results in the same error.
Set-DynamicDistributionGro
-365)).ToShortDateString()
I tried removing the ToStirng() and it results in the same error.
OK, given that ToShortDateString already converts to a string, what happens if you use this:
Regards,
Rob.
Set-DynamicDistributionGroup $ddg2 -RecipientFilter {(whenCreated -ge $(((get-date).adddays(-365)).ToShortDateString()) -and ((customattribute2 -like '*CLS*') -or (customattribute2 -like '*FA*') -or (customattribute2 -like '*AS*')) -and (alias -ne $null))}
Regards,
Rob.
ASKER
Rob, Thanks - but still no luck:
Set-DynamicDistributionGro up $ddg2 -RecipientFilter {(whenCreated -ge $(((get-date).adddays(-365 )).ToShort DateString ())) -and ((customattribute2 -like '*CLS*') -or (customattribute2 -like '*FA*') -or (customattribute2 -like '*AS*')) -and (alias -ne $null)}
Set-DynamicDistributionGro up : Cannot bind parameter 'RecipientFilter' to the target. Exception setting "RecipientFilter": "Invalid filter syntax. For a desc
ription of the filter parameter syntax see the command help.
"(whenCreated -ge $(((get-date).adddays(-365 )).ToShort DateString ())) -and ((customattribute2 -like '*CLS*') -or (customattribute2 -like '*FA*') -or (customat
tribute2 -like '*AS*')) -and (alias -ne $null)" at position 19."
At line:1 char:52
+ Set-DynamicDistributionGro up $ddg2 -RecipientFilter <<<< {(whenCreated -ge $(((get-date).adddays(-365 )).ToShort DateString ())) -and ((customattribute2 -lik
e '*CLS*') -or (customattribute2 -like '*FA*') -or (customattribute2 -like '*AS*')) -and (alias -ne $null)}
+ CategoryInfo : WriteError: (:) [Set-DynamicDistributionGr oup], ParameterBindingException
+ FullyQualifiedErrorId : ParameterBindingFailed,Mic rosoft.Exc hange.Mana gement.Rec ipientTask s.SetDynam icDistribu tionGroup
Set-DynamicDistributionGro
Set-DynamicDistributionGro
ription of the filter parameter syntax see the command help.
"(whenCreated -ge $(((get-date).adddays(-365
tribute2 -like '*AS*')) -and (alias -ne $null)" at position 19."
At line:1 char:52
+ Set-DynamicDistributionGro
e '*CLS*') -or (customattribute2 -like '*FA*') -or (customattribute2 -like '*AS*')) -and (alias -ne $null)}
+ CategoryInfo : WriteError: (:) [Set-DynamicDistributionGr
+ FullyQualifiedErrorId : ParameterBindingFailed,Mic
LOL! OK, fine....try this:
Or, would you settle for a two liner? Hopefully this works.
or
or
or
Regards,
Rob.
Set-DynamicDistributionGroup $ddg2 -RecipientFilter {(whenCreated -ge `'$(((get-date).adddays(-365)).ToShortDateString())`' -and ((customattribute2 -like '*CLS*') -or (customattribute2 -like '*FA*') -or (customattribute2 -like '*AS*')) -and (alias -ne $null))}
Or, would you settle for a two liner? Hopefully this works.
$oneyearago = $(((get-date).adddays(-365)).ToShortDateString())
Set-DynamicDistributionGroup $ddg2 -RecipientFilter {(whenCreated -ge $oneyearago -and ((customattribute2 -like '*CLS*') -or (customattribute2 -like '*FA*') -or (customattribute2 -like '*AS*')) -and (alias -ne $null))}
or
$oneyearago = $(((get-date).adddays(-365)).ToShortDateString())
Set-DynamicDistributionGroup $ddg2 -RecipientFilter {(whenCreated -ge '$oneyearago' -and ((customattribute2 -like '*CLS*') -or (customattribute2 -like '*FA*') -or (customattribute2 -like '*AS*')) -and (alias -ne $null))}
or
$oneyearago = $(((get-date).adddays(-365)).ToShortDateString())
Set-DynamicDistributionGroup $ddg2 -RecipientFilter {(whenCreated -ge `'$oneyearago`' -and ((customattribute2 -like '*CLS*') -or (customattribute2 -like '*FA*') -or (customattribute2 -like '*AS*')) -and (alias -ne $null))}
or
$oneyearago = "`'$(((get-date).adddays(-365)).ToShortDateString())`'"
Set-DynamicDistributionGroup $ddg2 -RecipientFilter {(whenCreated -ge $oneyearago -and ((customattribute2 -like '*CLS*') -or (customattribute2 -like '*FA*') -or (customattribute2 -like '*AS*')) -and (alias -ne $null))}
Regards,
Rob.
Sorry for all the attempts, I just can't test it, so I'm running a bit blind.
Rob.
Rob.
ASKER
Set-DynamicDistributionGro up $ddg2 -RecipientFilter {(whenCreated -ge `'$(((get-date).adddays(-3 65)).ToSho rtDateStri ng())`') -and ((customattribute2 -like '*CLS*') -or (customattribute2 -like '*FA*') -or (customattribute2 -like '*AS*')) -and (alias -ne $null)}
Set-DynamicDistributionGro up : Cannot bind parameter 'RecipientFilter' to the target. Exception setting "RecipientFilter": "Invalid filter syntax. For a desc
ription of the filter parameter syntax see the command help.
"(whenCreated -ge `'$(((get-date).adddays(-3 65)).ToSho rtDateStri ng())`') -and ((customattribute2 -like '*CLS*') -or (customattribute2 -like '*FA*') -or (cust
omattribute2 -like '*AS*')) -and (alias -ne $null)" at position 18."
At line:1 char:52
+ Set-DynamicDistributionGro up $ddg2 -RecipientFilter <<<< {(whenCreated -ge `'$(((get-date).adddays(-3 65)).ToSho rtDateStri ng())`') -and ((customattribute2
-like '*CLS*') -or (customattribute2 -like '*FA*') -or (customattribute2 -like '*AS*')) -and (alias -ne $null)}
+ CategoryInfo : WriteError: (:) [Set-DynamicDistributionGr oup], ParameterBindingException
+ FullyQualifiedErrorId : ParameterBindingFailed,Mic rosoft.Exc hange.Mana gement.Rec ipientTask s.SetDynam icDistribu tionGroup
The twoliners would work fine if this was code - but since it's a filter for a DDG I need it to be a one-liner.
Set-DynamicDistributionGro
ription of the filter parameter syntax see the command help.
"(whenCreated -ge `'$(((get-date).adddays(-3
omattribute2 -like '*AS*')) -and (alias -ne $null)" at position 18."
At line:1 char:52
+ Set-DynamicDistributionGro
-like '*CLS*') -or (customattribute2 -like '*FA*') -or (customattribute2 -like '*AS*')) -and (alias -ne $null)}
+ CategoryInfo : WriteError: (:) [Set-DynamicDistributionGr
+ FullyQualifiedErrorId : ParameterBindingFailed,Mic
The twoliners would work fine if this was code - but since it's a filter for a DDG I need it to be a one-liner.
Is it applied as a filter to a GUI in Exchange? I guess it's possible that when it's applied as a filter, cmdlets cannot be used.....
Try this:
If I echo the command in Powershell as Write-Host however, I cannot get it to evaluate the get-date expression. I think that's why the filter is unable to parse the query string.
Ultimately, it looks like the environment you're running the cmdlet in is unable to recognise it.
I will see if I can contact someone else to chime in who may know a bit more about that.
Rob.
Try this:
Set-DynamicDistributionGroup $ddg2 -RecipientFilter {(whenCreated -ge `'$(((get-date).adddays(-365)).ToShortDateString())`') -and (alias -ne $null) -and ((customattribute2 -like '*CLS*') -or (customattribute2 -like '*FA*') -or (customattribute2 -like '*AS*'))}
If I echo the command in Powershell as Write-Host however, I cannot get it to evaluate the get-date expression. I think that's why the filter is unable to parse the query string.
Ultimately, it looks like the environment you're running the cmdlet in is unable to recognise it.
I will see if I can contact someone else to chime in who may know a bit more about that.
Rob.
ASKER
Rob has done a lot of thought on this, but I was still waiting to see if he could get anything from his sources as the problem is unresolved.
Sorry...I'm still waiting on some clarification from some others...hopefully won't be too long.
Rob.
Rob.
@Rob, I just saw your message on the other post.
I look over this question and have done a few tests. I do not think this will work inside the RecipientFilter. I am not saying this can not be done I just could not figure it out inside the filter. I think your best option would be to use the two liners Rob posted before and run those as a separate script on a scheduled task to update this dynamic group everyday or however often you need it updated. Sorry I could not be more help.
I look over this question and have done a few tests. I do not think this will work inside the RecipientFilter. I am not saying this can not be done I just could not figure it out inside the filter. I think your best option would be to use the two liners Rob posted before and run those as a separate script on a scheduled task to update this dynamic group everyday or however often you need it updated. Sorry I could not be more help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Herculian effort. Tx.
(get-date).addDay(-365d)
to this
((get-date).adddays(-365))
Overall though, I think you didn't add the "s" to AddDay
Rob.