jPowerShell
jPowerShell copied to clipboard
Not able to print fail message
I am trying to revert to snapshot which doesn't exist.
Set-VM -VM windows10 -Snapshot snapshotvm123 -Confirm:$false
In the above command snapshotvm123
doesn't exist, so I want to print on the console a failed message with the command error message on the console.
Tried with response.isError but it says false
Error message while executing the command on PowerShell:
Set-VM : 03-11-2018 00:05:03 Set-VM Could not find Snapshot with name 'snapshotvm123'.
At line:1 char:1
+ Set-VM -VM windows10 -Snapshot snapshotvm123 -Confirm:$false
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (snapshotvm123:String) [Set-VM], VimException
+ FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_ObjectNotFound,VMware.VimAutomation.ViCore.Cmdle
ts.Commands.SetVM
Set-VM : 03-11-2018 00:05:03 Set-VM Snapshot parameter: Could not find any of the objects specified by name.
At line:1 char:1
+ Set-VM -VM windows10 -Snapshot snapshotvm123 -Confirm:$false
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (VMware.VimAutom...apshot Snapshot:RuntimePropertyInfo) [Set-VM], ObnRec
ordProcessingFailedException
+ FullyQualifiedErrorId : Core_ObnSelector_SetNewParameterValue_ObjectNotFoundCritical,VMware.VimAutomation.ViCore
.Cmdlets.Commands.SetVM
Hello,
https://github.com/profesorfalken/jPowerShell/wiki/New-3.0-version-of-PowerShell
The reponse method isError is not working as before. Instead of telling if the command was sucessful, now it will only return false in case the command did not work at all (timeout or unexpected error). If you want to know the result of the command you should use the new method isLastCommandInError
Best regards
Hi, I have similar issues: 1. The method isLastCommandInError does not return error when cmd-let is not recognized e.g. Write 'Set-NetFirewallRule : No MSFT_NetFirewallRule objects found with property but jPowershell returns no errors. 2. Another case. If there is syntax error, I got proper indication through the isLastCommandInError , but how to get error message to the string? Method getCommandOutput returns nothing in such a case.