Update VA Powershell

Guys. 

I am trying to update a VA with the value from a CSV file. 

Attribute1 is a DirectoryString VA. I have similar code that's works fine if the attribute is a BOOLEAN but trying to set this on a DirectoryString fails. 

#Set Runtime Parameters
$CSVImport = "C:\CSVFILE.csv"

Connect-QADService -Service "ARS-SERVER-Name" -Proxy
Import-Csv $CSVImport | ForEach-Object {
Set-QADUser -IncludedProperties 'Attribute1' -Identity $_.UserName -ObjectAttributes @{"Attribute1"=" $_.Url"}
}

Parents
  • 1. You don't need the '-IncludedProperties 'Attribute1' '.  This is only needed on "Get"

    2. For the Identity, I have gotten into the habit of explicitly casting to string - not strictly necessary coming from a file, but it just saves me headaches in general.

    -Identity [string]$_.UserName

    3.  Though probably functionally the same as what you are doing I would handle your URL property like this:

    -ObjectAttributes @{"Attribute1"=$([string]$_.Url)}

    Re 2 and 3, it's a bit of a belt and suspenders / braces approach but that's how I roll.

  • Hi. 

    Thanks. You learn something new every day. I have changed the code to below based on your suggestions. 

    #Set Runtime Parameters

    $CSVImport = "C:\CSVFILE.csv"

    Connect-QADService -Service "ARS-SERVER-NAMEt" -Proxy
    Import-Csv $CSVImport | ForEach-Object {
    Set-QADUser -Identity [string]$_.UserName -ObjectAttributes @{"Attribute1"=$([string]$_.Url)}
    }

    The error message is 

    DefaultNamingContext Type
    -------------------- ----
    CN=Active Directory ARS
    Set-QADUser :
    At line:6 char:5
    + Set-QADUser -Identity [string]$_.UserName -ObjectAttributes @{"Att ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Set-QADUser], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,ActiveRoles.ManagementShell.Powershell.Cmdlets.SetUserCmdlet

  • That's a weird error.

    What format is the username?  SamAccountName?  DistinguishedName?  Userprincipalname?

  • So for this script i am having to use UPN 

  • $CSVImport = "C:\CSVFILE.csv"

    Connect-QADService -Service "ARS-SERVER-NAMEt" -Proxy
    Import-Csv $CSVImport | ForEach-Object {

    $CurrentUser = [string]$_.UserName
    $AttributeContents = [string]$_.Url

    $TargetUser = Get-QADUser -LdapFilter "(userprincipalname=$CurrentUser)" | select -expandproperty DN

    Set-QADUser -Identity $TargetUser -ObjectAttributes @{"Attribute1"=$AttributeContents}
    }

Reply Children