I'm a little puzzled by how PowerShell treats a string that represents a DateTime when it comes down to parameters. My Script has a parameter definition as follows:
[CmdletBinding(DefaultParameterSetName='Kunde')]
param(
[Parameter(Mandatory=$true, ParameterSetName='Kunde')]
[string]$KdNr,
[Parameter(Mandatory=$true, ParameterSetName='Kunde')]
[DateTime]$von,
[Parameter(Mandatory=$true, ParameterSetName='Kunde')]
[DateTime]$bis,
[Parameter(Mandatory=$true, ParameterSetName='Kunde')]
[string]$Empfaenger
)
I want to enter the following date: 1. April 2016 as my locale string 01.04.2016
. Now PowerShell does something that is unexpected (at least to me):
- I enter the string
01.04.2016
at the command prompt when PowerShell queries the missing mandatory parameter. Then it gets parsed to 1. April 2016. - I enter the same string
01.04.2016
directly at the commandline like thisZippenUndMailen.ps1 -von '01.04.2016'
and now PowerShell parses the string using the US notation as January 4th 2016.
I've got two questions:
- Why does PowerShell parse the strings differently?
- How do I best remedy that behaviour? The Script should be reused and called both manually and via TaskScheduler and this behaviour is rather counter intuitive.