PSPushTeams icon indicating copy to clipboard operation
PSPushTeams copied to clipboard

.AddDays($) fails if $ is a var and only if scheduled via task scheduler

Open bwya77 opened this issue 7 years ago • 1 comments

Found when setting up scheduled tasks and adding start-transcript at beginning of script to see why it would 'pass' but never send.

Even if we set $maxPasswordAge = 90 it will still change it to 90.00:00:00. if it was set to 90.00 it would pass.

Var can be Int32 and still fail

Cannot convert argument "value", with value: "90.00:00:00", for "AddDays" to type "System.Double": "Cannot convert the "90.00:00:00" value of type "System.TimeSpan" to type "System.Double"." At C:\Automation\PSPush_expiryUsers2.ps1:42 char:3

  •     $expireson = $passwordsetdate.AddDays($maxPasswordAge)
    
  •     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [], MethodException
    • FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument

bwya77 avatar Dec 10 '18 21:12 bwya77

Current work around is to enter your max password age manually. $passwordsetdate.AddDays(90)

bwya77 avatar Dec 10 '18 21:12 bwya77