When I run my powershell command, one of my arguments is getting corrupted with another arg value. Why? This looks so simple .. but it's not working :(
param ( [switch]$help = $false, [string]$version, [string]$apiKey, [string]$source = $PSScriptRoot, [string]$destination = $PSScriptRoot, [string]$feedSource = "https://nuget.org", [string]$nuget, [switch]$clean = $false ) function CleanUpInputArgs() { Write-Host " **** " + $apiKey } CleanUpInputArgs Busted Example: $apiKey should be null or empty. NOT True. => & '.\foo.ps1' -version 123 -nuget aaaa -feedSource bbbb -clean True
Correct Example: $apiKey displays XXX. => & '.\foo.ps1' -version 123 -nuget aaaa -feedSource bbbb -clean True -apiKey XXX
As a side note, when i'm using Windows Powershell ISE, the -apiKey arg option does NOT show in the autocomplete drop down box ... ??? Related?
-clean), you need::-Clean:$true- otherwise, PowerShell will interpret your stringTrueas a positional argument to whatever parameter it may match