Skip to main content

Good evening,

I am creating an automation (in PowerShell) which adds VM to subclient. I use Add-CVVirtualMachine command, and it works pretty well, however I am not able to catch any (unseccesfull) outputs.

Example:

$aaa = Add-CVVirtualMachine -ClientName $VCenter -SubclientName $Subclient -EntityType VM -Entity $VMName

 

in case of errors $aaa is just null, despite on “INFO” showing:

 

INFO: Get-CVVirtualMachine: virtual machine not found having name nxxxxx]
INFO: PrepareContentBodyJson: virtual machine GUID not found for entity xxxxx]
INFO: Add-CVVirtualMachine: entity not found for add/remove virtual machine request

 

Thanks

Hello @Alexey Tesov 

Could you please check this link and let us know if it helps:

Best,

Rajiv Singal


Hello @Alexey Tesov 

Normally, if you run a Windows PowerShell command and an error occurs, the error record will be appended to the “automatic variable” named $error. When you use the -ErrorVariable parameter in a call to a command, the error is assigned to the variable name that you specify. It’s important to note that even when you use the -ErrorVariable parameter, the $error variable is still updated.

 

Please refer to following blog posts, they may be of some help to get output errors.

https://devblogs.microsoft.com/scripting/handling-errors-the-powershell-way/#:~:text=Normally%2C%20if%20you%20run%20a,variable%20name%20that%20you%20specify.

 

https://stackoverflow.com/questions/27861176/how-to-capture-error-output-only-in-a-variable-in-powershell

 


Hello @Alexey Tesov 

Normally, if you run a Windows PowerShell command and an error occurs, the error record will be appended to the “automatic variable” named $error. When you use the -ErrorVariable parameter in a call to a command, the error is assigned to the variable name that you specify. It’s important to note that even when you use the -ErrorVariable parameter, the $error variable is still updated.

 

Please refer to following blog posts, they may be of some help to get output errors.

https://devblogs.microsoft.com/scripting/handling-errors-the-powershell-way/#:~:text=Normally%2C%20if%20you%20run%20a,variable%20name%20that%20you%20specify.

 

https://stackoverflow.com/questions/27861176/how-to-capture-error-output-only-in-a-variable-in-powershell

 

Thank you for your answer @Tanuj Balani, but this way not gonna help me

 

The problem in my case that I do not expect any (classical) PowerShell error to be caught (like syntax or any other native PS errors) this is basically Add-CVVirtualMachine response which should be stored  in PSCustomObject (according to its documentation) but it is not. 2&>1 also gives me $null in this case (same story with $error variable) 🙁

 

So looks like there is no any elegance way to validate if onboarding was finalized successfully.

 

I think about using Get-CVVirtualMachine as onboarding validator


Hello @Alexey Tesov 

Yes, you can use Get-CVVirtualMachine to fetch the VMs in your CommCell environment.

You may refer to following documentation for information on syntax and optional parameters to use.

https://documentation.commvault.com/2023e/expert/101814_get_cvvirtualmachine.html


Reply