Powershell: Args/params not being populated
powershell
Solution
- Do not mix. Make use of $args or parameters.
- Also do note that $input is a special variable, don't declare it as a parameter. http://dmitrysotnikov.wordpress.com/2008/11/26/input-gotchas/
Problem
I have a PowerShell script: ``` param ( [Parameter(Mandatory=$true)][string]$input, [Parameter(Mandatory=$true)][string]$table ) Write-Host "Args:" $Args.Length Get-Content $input | % { [Regex]::Replace($_, ",(?!NULL)([^,]*[^\d,]+[^,]*)", ",'`$1'") } | % { [Regex]::Replace($_, ".+", "INSERT INTO $table VALUES (`$1)") } ``` The `Write-Host part` is for debugging. I run it as `.\csvtosql.ps1 mycsv.csv dbo.MyTable` (from powershell shell), and get ``` Args: 0 Get-Content : Cannot bind argument to parameter 'Path' because it is an empty s tring. At C:\temp\csvtosql.ps1:7 char:12 + Get-Content <<<< $input | + CategoryInfo : InvalidData: (:) [Get-Content], ParameterBinding ValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAl lowed,Microsoft.PowerShell.Commands.GetContentCommand ``` I get exactly the same error with any parameters that I pass, also the same error if I try to use named parameters. What can cause parameters not to be passed in? UPDATE: PowerShell ISE asks me for these parameters using GUI prompts, then gives me the same error about them not being passed in.