$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 

Parents
  • 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")

  • 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!

Reply
  • 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!

Children
No Data