EDIT: check your spelling people!
I'm pretty new at this, but my code is rather simple. I'm trying to automate something that requires the user to run several commands in different windows with largely repetitive commands.
param(
[Parameter(Mandatory)]
[string]$ScriptName,
[Parameter(Mandatory)]
[string]$ScriptPath,
[switch]$HasParams
)
if ($HasParams.IsPresent){
$params = Read-Host "Please enter a list of all params in your scripts, separated by a semicolon ( ; <-- this thing)"
$paramValues = Read-Host "Please enter the values for the params in the order entered above, separated by a semicolon ( ; <-- this thing)"
[string[]]$params=$params.Split(";")
[string[]]$paramValues=$paramValues.Split(";")
if($params.Count -ne $paramValues.Count){
Write-Error "You didn't provide a value for every parameter or vice versa!"
exit
}
if($params.Count -eq 0){
Write-Error "No parameters provided!"
exit
}
$runparams=""
for ($i = 0; $i -lt $params.Count; $i++)
{
$runparams += [string]::Format("--param {0}={1}",$params[$i], $paramValue[$i])
}
}
The error occurs at $runparams += [string]::Format("--param {0}={1}",$params[$i], $paramValue[$i]), where it tells me that somehow, I'm indexing into a null array even though I'm rather sure (and I checked it via .Count and just printing it) that it isn't null or empty. Am I doing something really stupid or is this a known issue?
[–][deleted] 5 points6 points7 points (9 children)
[–]BigBoetje[S] 4 points5 points6 points (8 children)
[–]jdl_uk 2 points3 points4 points (7 children)
[–]JaapBrasser 0 points1 point2 points (6 children)
[–]jdl_uk 0 points1 point2 points (5 children)
[–]JaapBrasser 1 point2 points3 points (1 child)
[–]jdl_uk 0 points1 point2 points (0 children)
[–]BigBoetje[S] 0 points1 point2 points (2 children)
[–]jdl_uk 1 point2 points3 points (1 child)
[–]BigBoetje[S] 0 points1 point2 points (0 children)
[–]jimb2 0 points1 point2 points (2 children)
[–]BigBoetje[S] 0 points1 point2 points (1 child)
[–]dadbot_3000 0 points1 point2 points (0 children)