Get all Vault users of a certain group

Issue

In Powershell all the Autodesk Vault users of a certain group should be determined via API.

Solution

The following function will return all users assigned to a given group:

function Get-UsersByGroup {
param (
[string]$GroupName
)
if(-not $vault) {
Write-Host 'Not connected to vault'
return
}
try {
$group = $vault.AdminService.GetGroupByName($GroupName)
       $users = $vault.AdminService.GetMemberUsersByGroupId($group.Id)
return $users
}
catch [Autodesk.Connectivity.WebServices.VaultServiceErrorException] {
if ($_.Exception.Message -eq 160) {
Write-Host 'Bad group name'
}
else {
Write-Host $_.Exception.Message
}
}
}
  • Check if there is an open connection to Vault
  • Request the groupID from Vault using the group name
  • Request group info for the retrieved groupID
  • Add all users in the group to an array and return the array

Example

To get all users of the group "Administrators" the function can be used like this:

Get-UsersByGroup -GroupName 'Administrators'
Example result:
Id           : 7
Name : TestAdmin
Email :
CreateUserId : 2
CreateDate : 11/16/2017 8:02:55 AM
IsActive : True
IsSys : False
Auth : Vault