I've simplified my situation as much as possible. I have a PowerShell script that programmatically starts a process with the "Run as administrator" option using the Start-Process cmdlet:
param
(
# Arguments to pass to the process, if any
[string[]] $ArgList
)
if($ArgList)
{
Start-Process -FilePath notepad.exe -ArgumentList $ArgList -Verb RunAs
}
else
{
Start-Process -FilePath notepad.exe -Verb RunAs
}
Since ArgumentList
cannot be NULL nor empty, I had to add the if-else
to avoid a ParameterArgumentValidationError error.
Everything works as expected with no problem, but I was just wondering if there's a more elegant (but still simple) way to accomplish that without using the if-else
blocks.