UpdateFileProperties from Vault-API in PowerShell

Sometimes you need generics like Lists or Dictionaries of different types in your PowerShell code, but you have just arrays or hashmaps. Here is my example:

Today I had the need to call this vault-API functionality from IExplorerUtils that wants a File object and a generic-dictionary. To get the File object was not the problem, but to pass my properties as Dictionary, that was really a big problem for me!

Heres the function I want to use to update the properties of my file:

void UpdateFileProperties( 
   File <!---->file<!---->,
   System.Collections.Generic.Dictionary<PropDef,object> <!---->props<!---->

The first working solution I tried was:

  • create an assembly in VisualStudio that references all the necessary Vault assemblies
  • write a small function that calls the UpdateFileProperties method of the ExplorerUtils
  • the function gets a hash or array, and converts it to a generic dictionary (thats very easy in c#)
  • in the PowerShell code you load your assembly and call your new function

But this workaround takes quite some time! Because of this here is a cleaner solution, that works with almost every type:

[System.reflection.Assembly]::LoadFrom("C:\Program Files (x86)\Autodesk\Autodesk Vault 2013 SDK\bin\Autodesk.Connectivity.Explorer.ExtensibilityTools.dll")
[System.reflection.Assembly]::LoadFrom("C:\Program Files (x86)\Autodesk\Autodesk Vault 2013 SDK\bin\Autodesk.Connectivity.Explorer.Extensibility.dll");
[System.reflection.Assembly]::LoadFrom("C:\Program Files (x86)\Autodesk\Autodesk Vault 2013 SDK\bin\Autodesk.Connectivity.WebServices.dll");
[System.reflection.Assembly]::LoadFrom("C:\Program Files (x86)\Autodesk\Autodesk Vault 2013 SDK\bin\Autodesk.Connectivity.Extensibility.Framework.dll");

#login to your vault and create a explorerUtlis object
$username ="Administrator"
$passw = ""
$login = New-Object -type Autodesk.Connectivity.WebservicesTools.UserPasswordCredentials $server,$vaultName,$username,$passw,$true
$vault = New-Object -type Autodesk.Connectivity.WebServicesTools.WebServiceManager $login
$ticket = $vault.DocumentService.SecurityHeaderValue.Ticket
$userId = $vault.DocumentService.SecurityHeaderValue.UserId
$explorerUtil = [Autodesk.Connectivity.Explorer.ExtensibilityTools.ExplorerLoader]::LoadExplorerUtil($server,$vaultName,$userId,$ticket)

#get your file where you want to update the properties
$file = $vault.DocumentService.FindFilesByPathsAndChecksums(@("$/test.bat"),@(0))[0]

#create your generic dictionary with properties and values
$propDefs = $vault.PropertyService.GetPropertyDefinitionsByEntityClassId("FILE")
$prop = $propDefs | Where-Object{$_.DispName -eq "Title"}
$propAndVals = New-Dictionary Autodesk.Connectivity.WebServices.PropDef system.Object

#pass your file and the dictionary and update the file props

Here you will find the functions for creating your generics and for reading the restriction code of the webservice expections: http://www.hawkee.com/snippet/9812/

About weiss92

Software Developer
This entry was posted in Uncategorized. Bookmark the permalink.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s