powershell - Working with dates in extensionAttributes and Get-Date -


i'm attempting use active directory extensionattributes keep track of dates (like start date, termination date, etc) can trigger actions when date occurs.

i'm having issue different variations date can entered in (m/d/yy, mm/dd/yy, mm/dd/yyyy, etc). example, can use get-date output format of m/d/yyyy, run issues when enters mm/dd/yy.

is there way make work can accept other variations (as long it's month/date/year)?

here couple of lines script in question. runs once day, , checks new users starting following day.

$startingon = (get-date).adddays(1).toshortdatestring()  $newusercheck = get-qaduser -dontusedefaultincludedproperties -includedproperties extensionattribute11 | { $_.extensionattribute11 -eq $startingon } 

notice how returns long date equals get-date output. way able work properly. @ that, if typed in 07/20/15, output return nothing.

don't try compare date strings. use datetime comparison won't care formatting details e.g.:

$startingon = (get-date).adddays(1) $newusercheck = get-qaduser -dontusedefaultincludedproperties -includedproperties extensionattribute11 |      { [datetime]($_.extensionattribute11) -eq $startingon} 

Comments