Passing DateTime as a parameter

I read widely that I can pass an argument to my powershell script through:

param ( [Datetime]$argument ) 

I also read that I can determine the default value:

 param ( [Datetime]$argument = Get-Date "5/1/2006 7:00 AM" ) 

However, with this I get:

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

It only seems to be for DateTime , any idea I'm wrong in?

+4
source share
1 answer

try to enclose the value in ()

 param ( [Datetime]$argument = (Get-Date "5/1/2006 7:00 AM") ) 
+12
source

All Articles