This article provides a solution by which you can enable Service Portal users to schedule snapshot reverts. The script provided will revert to the last snapshot for the target VM. If no snapshot exists, no action will be taken.
Because this solution is being offered as a command workflow, Service Portal users get access to it if their role has the Request Service Change permission. The permission Manage VM Snapshots is only used for the ad-hoc commands which are built into vCommander®.
Requirements
- Embotics® vCommander 5.7.7 or later
- Embotics vCommander REST API PowerShell client (2.7.3) & libraries
- PowerShell v4 installed on the vCommander application server
- vCommander script
- Encrypted vCommander credentials with REST API access
Preparing the Script
Download and extract the script to your vCommander application server. Embotics recommends storing all scripts called by vCommander in a single location, using sub-folders to identify the functions of scripts. With the script used for this solution extracted to C: on the vCommander server, the file system will look like this:
- C:\scripts\revertsnap\VM_snap_Automation.ps1
The script requires minor edits before it will work with your system.
Setting | Description |
$vCommanderServer | The hostname or IP address of the vCommander server. |
$Credfile | The credentials file which handles access to your vCommander. For more details refer to this knowledgebase article. |
Creating the Completion Workflow
Next, you will onfigure a Completion Workflow and make it available to Service Portal users as a command on their dashboard.
- Under the Configuration menu choose Service Request Configuration.
- Switch to the Completion Workflow tab.
- Click Add.
- Provide a Name and choose to apply the workflow after a change request is fulfilled, then click Next.
- Click Add > Execute Script and configure the step as follows, then click Next:
Step Name: Execute Revert Script
Step Execution: Always Execute
Timeout: 300
Script Output: Capture script output as comment
When Step Fails: Mark workflow step as failed: do not proceed
Command Line:
powershell.exe -ExecutionPolicy Bypass &{C:\Scripts\VM_Snap_Automation.ps1 '#{target.remoteId}'} - Choose Do not apply this workflow to any form (this will be handled in the next section). Click Next.
- Click Finish.
Creating the Change Request Form
Next, create a change request form and associate it with the workflow.
- Under the Configuration menu, choose Service Request Configuration.
- Switch to the Form Designer tab.
- Under the Form Library section, click Add.
- Configure the form as follows, and click OK:
Form Name: Revert VM Snapshot
Display Name: Revert VM Snapshot
Form Type:Change Request Form
Completion Workflow: Revert VM Snapshot
Publish globally or to specific organizations, groups and users.
Optionally add text to the form explaining the behavior of the workflow:
Users with permission to submit change requests will now be able to request and/or schedule the snapshot revert.