код -
# Get current Year and Month
param ([Int]$Year, [Int]$Month, [String]$Environment, [String]$Report, [String]$Username, [String]$Password)
function Get-DaysOfMonth {
Param ([Int]$Year, [Int]$Month)
$MonthDays = New-Object System.Collections.Generic.List[System.Object]
1..([datetime]::DaysInMonth($Year, $Month)) |
ForEach-Object {
$Day = ([datetime]::ParseExact("$_/$Month/$Year", "d/M/yyyy", [System.Globalization.CultureInfo]::InvariantCulture)).ToString("dd")
$MonthDays.Add($Day)
}
return $MonthDays
}
Write-Host "The Year Selected is: " + [String]$Year
Write-Host "The Month Selected is: " + [String]$Month
Write-Host "The Environment Selected is: $Environment"
Write-Host "The Report Generated is: $Report"
Write-Host "Export Generating as User: $Username"
$Days = Get-DaysOfMonth -Year $Year -Month $Month
При запуске я получаю следующую трассировку:
Cannot process argument
transformation on parameter 'Year'. Cannot convert value "Year" to type
"System.Int32". Error: "Input string was not in a correct format."
+ CategoryInfo : InvalidData: (:) [myscript.ps1], ParentContai
nsErrorRecordException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,myscript
.ps1
Кажется, у него проблема с преобразованием моей переменной Integer в строку. Как мне это исправить?
Я запускаю скрипт по следующей команде
myscript.ps1 -Year 2018 -Month 02 -Environment PROD -Report event -Username myacct -Password mypass