Issue

For some task it is necessary to know which Vault user created a job. For example when their name is required in the job or their email address.


Solution

You have to get the user's id from the job in the job queue. With that id you can retrieve the matching user object.

function GetJobCreator {
<#
.SYNOPSIS
Returns a Vault user object
.DESCRIPTION
This function checks if the current user has permissions to retrieve the user information. If it doesn't the function logs a warning and does nothing. If it does the function returns an Autodesk.Connectivity.WebServices.User object. 
This function was made for Vault 2018
.EXAMPLE
$JobCreator = GetJobcreator -JobId $powerjobs.Job.Id
$JobCreator.Name
$JobCreator.Id
$JobCreator.Email
#>
param(
[long]$JobId
)
    if(-not $vault.JobService.CheckRolePermissions(@("GetJobsByDate"))) {
        Add-Log "User needs 'JobQueueRead' permission to execute GetJobsByDate"
        return
    }
    if(-not $vault.AdminService.CheckRolePermissions(@("GetUserByUserId"))) {
        Add-Log "User needs 'AdminUserRead' permission to execute GetUserInfoByUserId"
        return
    }
 
    [array]$allJobs = $vault.JobService.GetJobsByDate([int]::MaxValue,[DateTime]::MinValue)
    $currentJob = $allJobs | ? { $_.Id -eq $JobId }
    $user = $vault.AdminService.GetUserByUserId($currentJob.CreateUserId)
    return $user
}


Remarks

In order to use this with an older Vault version the calls to CheckRolePermissions have to be removed