$DirObj.get("Virtual Attribute")

Hi. 

Can $DirObj.get(" ") be used to get the value of a Virtual Attribute? I know it can grab SamAccountName etc but not sure about VA.

I need to grab the value of a VA to use in a Powershell script i am running as part of a Workflow. Is looking it up via Get-QADUser the only way? 

Thanks in advance 

  • With VA's, their values need to be loaded into the cache and then retrieved. Replace the name of actual VA in this code snippet.

    # Load the VA in question to the cache and get its value
    [void]($DirObj.GetInfoEx(@('edsvaAttribute'),0))
    $VAValue = $DirObj.Get("edsvaAttribute")

  • Hi Craig

    Yes, if you have a look at PowerShell Library Source Code - Wiki - Active Roles Community - One Identity Community, there is a function list called GetActualAttribute, this function has two parameters

    $AttributeName = This it he attribute you want a value for, IE "edsvaYourAttribute"

    $ADSIObject= this is your current object, IE $Request

    The function checks if the attribute you have supplied has been changed in the request, if it has it returned that value, otherwise it checks DirObj, and returns that value.

    Hope that helps.

  • To add to Richard's answer, I've found that the line:

    $VAValue = $DirObj.Get("edsvaAttribute")

    may produce a terminating error if the object in question doesn't actually have a value in "edsvaAttribute". At least it's a terminating error in Active Roles scripted policies - I would assume the same for the Sync Service. Hence, you may wish to introduce error handling:

    try {
        $VAValue = $DirObj.Get("edsvaAttribute")
    }
    catch {}
    if ([string]::IsNullOrEmpty($VAValue)) {
        # Do something if the attribute is null
    }
    else {
        # Something else if the attribute is populated
    }

    Hope that helps!