When using the vCAC mgmtContext you can get and set any exposed property in the repository. When I recently used that to set the “CurrentTask” property of a VirtualMachine object I noticed that the initial value of the property was “null” but when I wrote a PowerShell ‘$null’ value into it to reset it to its initial state, actually an empty string was saved to the property.
After some investigation of the ODATA REST stream I found that the underlying data type was derived from ADO DataServices. However, here a ‘null’ string is treated differently: as a special attribute ‘m:null’ within the property. After some fiddling with PowerShell I found that you can emulate this with the following expression:
$vm.CurrentTask = [NullString]::Value; $m.UpdateObject($vm); $m.SaveChanges();
The REST stream then looks like this (check the highlighted line):
MERGE https://vcac52/Repository/Data/ManagementModelEntities.svc/VirtualMachines(guid'2b29a665-4612-4712-83c5-ffa87f3d6f30') HTTP/1.1 User-Agent: Microsoft ADO.NET Data Services DataServiceVersion: 1.0;NetFx MaxDataServiceVersion: 2.0;NetFx Repository-Cache: AuthorizationStore=Fri, 25 Oct 2013 13:50:45 GMT;ModelConfiguration=Mon, 14 Oct 2013 14:38:27 GMT;ReadPermissions=Wed, 19 Jun 2013 01:45:17 GMT;WritePermissions=Wed, 19 Jun 2013 01:45:45 GMT Accept: application/atom+xml,application/xml Accept-Charset: UTF-8 Content-Type: application/atom+xml Authorization: Negotiate 1XhGSgpeHs/t1u2M+ySIDsiLYQ2pcJ6uOt1Qecx+DBrEAlg/uwIIDVYDPbyQqU8bZ3lMB5r+BkDoOfECKGDbg13s8AVQHzExyvp2qYszPLiA59WtgO6bhL1POGsMF9jwoqCt6HA= Host: vcac52 Content-Length: 3533 Expect: 100-continue <?xml version="1.0" encoding="utf-8" standalone="yes"?> <entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom"> <category scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" term="DynamicOps.ManagementModel.VirtualMachine" /> <title /> <author> <name /> </author> <updated>2013-10-25T13:52:24.5694839Z</updated> <id>https://vcac52/Repository/Data/ManagementModelEntities.svc/VirtualMachines(guid'2b29a665-4612-4712-83c5-ffa87f3d6f30')</id> <content type="application/xml"> <m:properties> <d:BlueprintType m:type="Edm.Byte">1</d:BlueprintType> <d:ConnectToVdi m:type="Edm.Boolean">false</d:ConnectToVdi> <d:CurrentTask m:null="true" /> <d:ExpireDays m:type="Edm.Int32">1</d:ExpireDays> <d:Expires m:type="Edm.DateTime">2013-10-16T08:58:03.307</d:Expires> <d:FileLevelCloneImageName m:null="true" /> <d:Flags m:type="Edm.Int64" m:null="true" /> <d:GuestOS m:null="true" />
Once more, PowerShell to the rescue …