In azure Powershell I use the command "az vm run-command invoke" to execute scripts to virtual machines, the problem is when for some reason it doesn't work, it prints in the error message all the parameters'value in clear, and these parameters are sensitive data that I don't have to print in the error message for security reason.
This is what I try to execute:
az vm run-command invoke -g $ResourceGroupName -n $VMname[-1] --command-id RunPowerShellScript --scripts @$pathScript --parameters "param1=$($Data1)" `
"param2=$($Data2)"
In my case, Data1 can be sensitive, I never print that value in the code, but in the error message the value is shown in clear, and I don't have to allow that.
Keep in mind that the script defined in @$pathScript and executed in the machine works well when I add the right parameters.
I tried by puting the code into a try catch block, but this is still throwing the error message and it doesn't print the message added in the catch part
try{
az vm run-command invoke -g $ResourceGroupName -n $VMname[-1] --command-id RunPowerShellScript --scripts @$pathScript --parameters "param1=$($Data1)" `
"param2=$($Data2)"
}catch{
Write-Error "Error : Please check if your are passing the good arguments - Check the code if you need and debug it"
}
What am I missing?.