The power of shell – PowerShell commandlets for Vault

We built a new layer on top of the Autodesk API. This layer allowes to perform common operations via a single PowerShell-call on the Vault Server. We can say that this layer is made for newbies, who are neither familar with the Vault API, nor with .Net coding. It’s not made for people who want to do very complex things, but it covers a large area of different operations that a Vault programmer has to do every time he starts writing code against Vault!

powerJobs uses this layer in all it’s default scripts and modules. And because this layer is used, compatibility and maintainability is now much better than before. Just have a look at the scripts: the first thing that you’ll notice is, that the number of lines of code went down from over 70 lines to around 20. And that’s why I like it so much.

This is probably everything that I have to explain about it. I rather show you what it can do, and why it is so powerful:

1. Reading file properties

I don’t want to show you the code that you need in order to get the values of some file properties. I think you did it already a couple of times: first, you have to get the PropDefs, then you have to filter out the PropDefs that you need. After that, you have to retrieve the PropInst objects, …. You see, there is a lot to do just to get a property value.

Instead, use our layer and this code:

$file = Get-VaultFile -File "$/Designs/Pad Lock.iam"
$file.MySpecialProperty

This is not a miracle! All the UDP and system-properties are attached on the file object from the layer. And there is much more: this file object is so intelligent, that it converts the properties already into the right types:

#this is a system property of type DateTime where you can call DateTime functions
$file.'Date Modified'.DayOfWeek

2. Adding files to Vault

If you are not familar with Vault, you don’t know the concept of checking in and out files. If you want to add a file to Vault, you have first to check if the file already exists. If not, you have to perform an AddFile. If it exists, you have to check out the existing file and check in the file as a new version. The layer tries to hide this process behind an ease-to-use Add-VaultFile command-let that handles all these things for you:

$file = Add-VaultFile -From "C:\Temp\someFile.ipt" -To "$/Test.ipt"

3. Finding files

It provides functions to find files in Vault. The syntax is as easy as you think:

# you can search by properties and use wild cards
$files = Get-VaultFiles -Properties @{'Name'='Catch *.iam'}

# you can also search for more properties than just one
$files = Get-VaultFiles -Properties @{'File Extension'='iam';'State'='Released';'Title'='Hallo World!'}

# or do you want to get all the files from a specific folder?
$files = Get-VaultFiles -Folder "$/Designs"

4. Updating UDP’s, category, state and revision

To modify data on the Vault file, you can use the function Update-VaultFile. It compresses all the power you need to perform default update operations like updating file properties, states, categories, dependencies, comments, attachments, classification and so on.

# let's update some property values
Update-VaultFile -File '$/Padlock/Catch Assembly.iam' -Properties @{'Title'='Martin';'Engineer'='Manuel'}

# and now we change the category and the revision and set a comment
Update-VaultFile -File '$/Padlock/Catch Assembly.iam'  -Category 'Engineering' -Revision 'B' -Comment 'this is a test'

5. Working with file associations

This is a very hot topic, because the vault API allows a lot of configurability here. Our command-lets are covering the most often used cases: getting dependencies, getting attachments, setting dependencies and attachments, adding them, removing them and downloading them.

# getting the dependencies
$childs = Get-VaultFileAssociations -File '$/Designs/postBCP/Assembly1.iam' -Dependencies

# getting attachments only
$attaachements = Get-VaultFileAssociations -File '$/Designs/postBCP/Assembly1.iam' -Attachments

#adding a file and adding it as attachement
$parent = Get-VaultFile -File "$/Test1.iam"
$child = Add-VaultFile -From "C:\Temp\test.ipt" -To "$/Test2.ipt"
Update-VaultFile -File $parent.'Full Path' -AddAttachments @($child.'Full Path') -Comment "Added an attachment"

6. Downloading files

What do you think? Which command-let will download your Vault file? Of course, it is the Get-VaultFile command-let. If you want to download the file, you just have to tell it where to store the download like this:

$padlock = Get-VaultFile -File "$/Designs/Padlock.iam" -DownloadPath "C:\Temp\Padlock"
echo $padlock.LocalPath

Just set the path where to download the assembly and it will perform a very intelligent download. You have no configuration possibilities like with the Vault API, but it does its job very well: it downloads the file in a way, that it can be opened without problems! This means, it will download all its dependencies, it will keep the folder-structure like in Vault, it will not rename the files, and update the references.

 

You see, it gives you all the power to perform very common operations on your Vault!

It is meant to be used by newbies, by administrators without very detailed knowledge about programming and also by PowerShell gurus who want to write short and clean scripts!

More commandlets will come in the future, so if you miss a commandlet or have a suggestion, then just leave a comment or reach out to us directly. All these commandlets are part of powerJobs 2015 R2, which will be released in the next days!

About weiss92

Software Developer
This entry was posted in powerGate, powerJobs, PowerShell, Uncategorized, Vault API and tagged . Bookmark the permalink.

3 Responses to The power of shell – PowerShell commandlets for Vault

  1. Pingback: powerJobs – A new UI experience | coolorange

  2. excellent publish, very informative. I wonder why the opposite
    experts of this sector do not notice this. You must proceed your writing.
    I’m confident, you have a huge readers’ base already!

  3. Everything is very open with a very clear explanation of the issues.
    It was definitely informative. Your website is very helpful.
    Thank you for sharing!

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