vCAC: Using the .NET ODATA REST Client from PowerShell

As you know vCAC provides a REST interface for its repository that you can use to manipulate most of its entities. Although the calling convention for this (ODATA based) REST interface is quite clear and among others Tom provided a few hints and some sample scripts on how to query things it is quite a burden to get this on to a production like level. However, there is help … As I described in an earlier post all vCAC workflows get a so called ‘mgmtContext‘ which in .NET reality is a ‘DynamicOps.ManagementModel.ManagementModelEntities’ object that resides in the ‘DynamicOps.ManagementModel.Client.dll’. This is actually a complete wrapper for the REST interface that comes in the form of an assembly. That in turn means you can use it from PowerShell; and furthermore: that you can also use it from external systems. All you have to do is use the following code to do a request:

Add-Type -Path ("{0}\VMware\vCAC\Server\DynamicOps.ManagementModel.Client.dll" -f ${ENV:ProgramFiles(x86)});

if(!$cred) { $cred = Get-Credential; };
$m = New-Object DynamicOps.ManagementModel.ManagementModelEntities -ArgumentList 'https://vcac52/Repository/Data/ManagementModelEntities.svc';
$m.Credentials = $cred;
$m.GetMetadataUri();
$m.VirtualMachines.VirtualMachineName;

And you actually need the following assemblies on the system where you make the call:


DynamicOps.ManagementModel.Client.dll
DynamicOps.ManagementModel.Common.dll
DynamicOps.Repository.dll

Much easier than writing a complete REST wrapper for it yourself – especially when coding ‘MERGE’ requests to update and save changes  …

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: