Passing DateTime as a parameter

Question:

I’ve read widely that I can pass in an argument to my powershell script via:

I’ve also read that I can define a default value:

However on doing this I get:

At C:\Users\medmondson\Desktop\Scripts\ScrumTimer.ps1:2 char:26
+ [Datetime]$argument = Get-Date “5/1/2006 7:00 AM”
+ ~ Missing expression after ‘=’. At C:\Users\medmondson\Desktop\Scripts\ScrumTimer.ps1:2 char:24
+ [Datetime]$argument = Get-Date “5/1/2006 7:00 AM”
+ ~ Missing ‘)’ in function parameter list. At C:\Users\medmondson\Desktop\Scripts\ScrumTimer.ps1:3 char:1
+ )
+ ~ Unexpected token ‘)’ in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingExpressionAfterToken

This only appears to occur for DateTime, any idea where I’m going wrong?

Answer:

try enclose value in ()

Source:

Passing DateTime as a parameter by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply