I am trying to pass the file name as argument to powershell. When i was checking the condition with test-path it throws exception.
if ( Test-path -path $argv[0] ) {
&"$MsbuildBinPath\Msbuild.exe" $MSBuildFile "/t:BuildAll" "$Logger" "$ErrorLogger" "/p:AllComponents=$argv[0]"
if ($LastExitCode -ne 0) {
Write-Host "It failed, send a mail"
}
I am trying to call it like follows
U:\Scripts>Powershell -file "U:\Scripts\Build.ps1" List.txt
It is throwing exception as follows
Cannot index into a null array.
At U:\Scripts\Build.ps1:37 char:29
+ if ( Test-path -path $argv[ <<<< 0] -IsValid ) {
+ CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Looks like a typo. There’s no variable with that name – $argv, change it to $args.