Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing DateTime as a parameter

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

param (
    [Datetime]$argument
)

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

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

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?

like image 581
m.edmondson Avatar asked Dec 06 '22 08:12

m.edmondson


1 Answers

try enclose value in ()

param (
    [Datetime]$argument = (Get-Date "5/1/2006 7:00 AM")
)
like image 152
CB. Avatar answered Dec 13 '22 20:12

CB.