Contact & Subscribe RSS

LinkedIn
RSS

PowerShell Rest API programming

With the PowerShell invoke-restmethod command it’s possible to interact with a REST based API.
In the following script I’ve added a couple of examples how-to interact with methods as GET and POST.

Add VM to VEEAM Portal scope with PowerShell and the VEEAM Rest API

The steps taken in this script:
– Creating a new session with the given credentials.
– Search for the VMid (GET query).
– Search for the right account. (GET query)
– Add VM To portal scope (POST with XML body).

*note: No error/exception handling added, just a beginners script to show howto interact with the VEEAM Rest API with PowerShell.

 

Add VM to VEEAM Backup job using PowerShell

I created a simple PowerShell function to add VM’s in a VEEAM backup job. This script has 2 options, enable indexing  and/or application aware processing per object.

There are many more possibilities to add functionality. For now, it fits our needs. If you have some feature requests, please comment below.

It can be used by VMWare and Hyper-v users; it checks the hypervisor in the beginning.
Run this script on a VEEAM VBR Server.

Together we can improve this PowerShell function, don’t hesitate to comment.
Deleted some bugs 23-01-2017

 

Monitor VMM Job using PowerShell

In SCVMM there is no option to send a mail when a job is completed.
This can be archived with PowerShell. Here is an simple example script to monitor the SCVMM Job status:

 

Compact Dynamic VHDx file

There are many ways to compact a VHDx file. It can be done using SCVMM, Hyper-V manager or even diskpart.
In my situation the compact option doesn’t reduce the size, it was even bigger than before the compact.

I’ve tried to defragment the disk, migrate it or even clean it up inside / without any result.
The only way to get this job done is writing zero’s on the empty space.

This can be done with the tool SDelete, created by Mark Russinovich. The tool zeroes the empty space within the VHDx file.
Before running the tool delete al the un-needed and temporary files.

Sam Boutros created a nice little PowerShell function to get this job done. The package with SDelete and the script can be downloaded HERE.
Example script function parameters:

After running the tool the compact action will reduce the space.
Since Windows 2012 Microsoft has the new TRIM/UNMAP command founded, this works only when the Underlying storage supports this.

 

Create test alert in SCOM

There is no standard feature in SCOM to generate a test alert, which can be needed to test a mail subscription.
For SCOM2007 there is a simple tool to generate test alerts. Too bad that this tool doesn’t support SCOM2012.
If you are using SCOM2007 you can download the tool here: http://blogs.technet.com/b/momteam/archive/2009/05/19/notifications-test-tool.aspx

For the SCOM2012 users we can generate a test alert with a Microsoft Event log event.
First we need to create an event log entry. This can be done with PowerShell or a CMD Command.

Create event in Windows Event log

I’ve done this with the standard EventCreate command in CMD.
eventcreate /L Application /T information /ID 999 /D “This is a test event” /SO TestEvent

If you want to create a daily test event, this can be scheduled in task scheduler.

Sample parameters:
– Run whether user is logged on or not
– Run with highest privileges
– Program/script: eventcreate
– Arguments: /L Application /T information /ID 999 /D “This is a test event” /SO TestEvent

Create an Event Monitor in SCOM

  • Go to the Authoring tab -> Monitors -> Create a unit monitor.
  • Create a new management pack: “Test event management pack” Or use (not the default) a other unsealed management pack.
  • Choose Windows Events -> Simple event detection -> Timer reset.
  • Give it a name, and select the target. I’ve chosen the “Operations Manager Management Server Computer Group” because i generate the test event on my SCOM Management server.
  • I’ve chosen the “configuration” parent monitor because this is a typical configuration thing.
  • Select the event log we are monitoring for the event.
  • Next, type the Event ID (999) and the Source (TestEvent).
  • Configure the timer when the test alert can be closed.
  • Configure the Severity and Priority and Select the “Generate alerts for this monitor” box.

Now you can test Alerts with running the scheduled task or run the command in the DOS prompt.

Get Cluster Shared Volume (CSV) free space with PowerShell

With the failover cluster manager it’s hard to summarize the free space for each CSV.
Here is a sample script to determine the free space for the Cluster Shared Volumes in each Hyper-V cluster.

 

 

Delete dependencies Default Management Pack

Default Management Pack Information

Don’t save any custom rules, overrides or views to the default management pack. Store al application specific overrides in a new unsealed application overrides MP. Or when the overrides are customer based, create an unsealed customer management pack. When this is done, you can simply delete application specific or customer specific overrides.
Now with the rule above in your mind, we are going to delete al the dependencies in the default management pack.

SCOM Reporting Overrides Report.

With this report its possible to locate overrides saved in the Default Management Pack.
If there is some override made, locate the monitor or rule and go to the override summery to delete the overrides.
After this step, try to delete the Management Pack. Same situation? Go to the second step.

SCOM XML Management pack editing:

The default management pack is an unsealed management pack with the real name “Microsoft.SystemCenter.OperationsManager.DefaultUser”. Unsealed Management Packs like all SCOM handmade management packs can be edited.
Export the Default Management pack 2 times, first on your backup location and second one witch you going to edit.
There are four sections in the management pack:
– Manifest: Contains the name of the management pack and the references.
– Monitoring: Contains the monitoring and override definitions.
– Presentation: Contains the views and folders.
– Language Packs: Contains readable names for objects instead of unreadable system guides.

When you have deleted all overrides on monitors and deleted al the views the reference section in the XML is the issue. So first delete the references:

Delete all <Reference Alias= </Reference> for each Management Pack that must be removed.

Example Advisor:

In my situation was this enough to delete the management pack. Because I had delete the overrides and views in the SCOM UI.

Save the XML, and import the management pack again. When importing the management pack, this will be trowed: Default Management Pack version 7.1.10226.0 is imported. Click install.

When there are still dependencies on the management pack, safely remove the dependent overrides, monitors and views in the other 3 sections based on the management pack you want to remove. The example formats are:

 

VEEAM Change disk exclusion (disk filter) with PowerShell

When you have multiple jobs with many VMs it’s a boring task to change all the disk exclusions by hand. That’s why VEEAM have made a nice PowerShell module to automate this boring tasks.

Excluded disks are displayed with numbers, the numbers in Hyper-V are different (because of the IDE disks) then how the numbers are showed in VMWare.
This scripts are tested with VEEAM Backup and Replication V8.

See the current excluded disks and the numbers with this script (Run as Administrator):

Change the disks exclusions with PowerShell (Run as Administrator):

Comments are welcome.

Task failed. Failed to expand object. Error: Object was not found

Task failed. Failed to expand object. Error: Object was not found

Change VM ID VEEAM database.
In my case I had to replace the old VM id with the new one.

There are multiple reasons why the VMID is changed. This can be caused by exporting and importing the VM for example. When this situation occurred you get the following error in VEEAM:
“Task failed. Failed to expand object. Error: Object was not found”

If you don’t want to add the new object and creating a new full back-up of the VM. You can change the VM ID in the database.

When this is done the forward incremental runs as before.

First we need to determine the OLD id where VEEAM is looking for.
This can be done with the following lines SQL Query against your VEEAM DB:

Get old object ID before Veeam version 9.5

Get old object ID Veeam 9.5

The following step is to get the new VMID from Hyper-V or VMWare.
With Hyper-V Virtual Machines Manager (SCVMM) PowerShell Module.

Run PowerShell as Administrator:

With VMWare can this be done with PowerCLI on the ESX host.
Excuse me when I’m wrong, but I think:

SQL Query:

Put the new ID by SET.
Put the old ID by WHERE.

*Tested with VEEAM Backup & Replication 8

 

CSV IO Paused during Back-up

Finally there are hotfixes for the annoying CSV IO Paused during the back-up. The issue mostly occurs when multiple CSV VSS Snapshots are initiated. I’ve tested the hotfixes in my test envoirement and the issues seems to be gone now.

The components:

KB3090343 https://support.microsoft.com/en-us/kb/3090343
Component: Clussvc.exe
Resolves an issue when multiple VSS backups are in progress, the cluster service may crash because of inconsistent state in the CSV VSS provider.

KB3060678 https://support.microsoft.com/en-us/kb/3060678
Component: Volsnap.sys
Resolves an issue where unneeded snapshots may not be deleted after a backup is completed. This prevents future backups from failing due to a lack of free space consumed by snapshots.

KB3063283 https://support.microsoft.com/en-us/kb/3063283
Component: Hyper-v Integration Services
Increases the time-out to detect the volumes to shadow copy when the Guest OS has multiple volumes.

KB3072380 https://support.microsoft.com/en-us/kb/3072380
Component: Rdvgpuinfo.dll / Vmms.exe
Resolves an issue on a Hyper-V cluster where the heartbeat component times out during a long-running snapshot. The snapshot fails and the VM restarts.

The full list of Microsoft Cluster Hotfixes:
https://support.microsoft.com/en-us/kb/2920151