How to get an user's first and last name in Vault 2022 and newer

How to get first name and last name of a Vault user in Vault 2022 and newer via Vault API

Before Vault 2022 "first name" and "last name" were properties on the Vault user object. In Vault 2022 there were changes to the API that make additional code necessary to read those. The two values are now considered profile attributes and there are a couple of new functions related to profile attributes.

  • AddProfileAttributeDef
  • DeleteProfileAttributeDef
  • GetProfileAttributeDefs
  • GetProfileAttributes
  • SetProfileAttributeOrder
  • UpdateProfileAttributeDef

In order to read attribute values the following two functions are needed:

 Sample function

The following function returns the value of a profile attribute based on the passed in display name. The display name might differ based on your Vault language.

function Get-VaultUserAttribute {
  param (
      $AttributeName,
      $VaultUserId
    )

  $userProfileAttributeDefinitions = $vault.AdminService.GetProfileAttributeDefs([Autodesk.Connectivity.WebServices.ProfileAssoc]::User)
  $attributeDefinition = $userProfileAttributeDefinitions | Where-Object { $_.Name -eq $AttributeName }
  $profileAttributes = $vault.AdminService.GetProfileAttributes(@($VaultUserId), @($attributeDefinition.Id))
    $attributeValue = $profileAttributes | Where-Object { $_.AttrId -eq $attributeDefinition.Id } | Select-Object -ExpandProperty Value

    return $attributeValue
}

Open-VaultConnection
Get-VaultUserAttribute -AttributeName 'First Name' -VaultUserId $vaultConnection.UserID
Get-VaultUserAttribute -AttributeName 'Last Name' -VaultUserId $vaultConnection.UserID

 

To get a list of available user attributes you can use the GetProfileAttributeDefs function.

Open-VaultConnection
$vault.AdminService.GetProfileAttributeDefs([Autodesk.Connectivity.WebServices.ProfileAssoc]::User)