This is the content of the my_script.ps1 file:
function InitDotnet {
param (
[Parameter(Mandatory)]
[string]
$ProjectName,
[Parameter(Mandatory)]
[ValidateSet("cli", "lib")]
[string]
$ProjectType,
[Parameter]
[bool]
$Xunit = $false,
[Parameter]
[bool]
$Src = $false
)
Write-Host "Name:" $ProjectName
Write-Host "Type:" $ProjectType
Write-Host "Create a xunit project:" $Xunit
Write-Host "Create a src folder:" $Src
}
InitDotnet $args[0] $args[1] $args[2] $args[3]
First, I don't know why the default bool values don't work.
.\my_script.ps1 Test lib
Name: Test
Type: lib
Needs xUnit:
Create a src folder:
And I can't pass Boolean arguments to my .ps1 script without casting errors.
.\my_script.ps1 Test lib $true
InitDotnet : Cannot process argument transformation on parameter 'Xunit'.
Cannot convert value "True" to type "System.Management.Automation.ParameterAttribute".
Error: "Invalid cast from 'System.Boolean' to 'System.Management.Automation.ParameterAttribute'."
What am I doing wrong?