I’d take a hash table. They’re better at variable data.
MyScript.ps1 -data @{‘Name’=‘Joe’;‘Country’=‘whatever’}
param(
$data
)
It’s easy enough to enumerate through $data, then. If each run of the script represents a single user, then $data will contain keys for $data.Name, $data.Country, and whatever else exists. You can use $data.KeyExists(‘Name’) to determine if a key exists or not.
If $data contains more than one user’s worth of info:
MyScript.ps1 -data @(@{‘Name’=‘Joe’;‘Country’=‘whatever’},@{‘Name’=‘Doug’;‘Department’=‘IT’})
You’d then ForEach through each element in $data
ForEach ($thing in $data) {}
And $thing would be a hash table, with keys, the KeyExists() method, etc.
This way, each element has a name - you’re not just relying on positional input, which is hard to maintain and read. Each element can have variable keys, so not every element needs to be defined.
Part of your original problem, incidentally, is this whole positional thing. You’re coding this like it’s C#. Even if you had:
Param(
$name,
$city,
$state,
$department
)
You don’t have “blanks” per se. You’re only thinking that because you’re using positional input rather than named input.
MyScript.ps1 -name Don -city Vegas -department “Info tech”
That approach - which is how PowerShell’s really meant to work - means I can safely omit State. I’m explicitly naming each piece of input, so PowerShell knows what goes where. So you could go that approach as well, if you like.