Using customattributes

Welcome Forums General PowerShell Q&A Using customattributes

This topic contains 1 reply, has 2 voices, and was last updated by

1 year, 12 months ago.

  • Author
  • #67420

    Points: 0
    Rank: Member

    I have a simple user creation script that works great except for extensionattributes. I'm having issues with the autopopulate/translation of the extenstion attributes. I'm familiar with set-aduser and the process of adding extension attributes but with New-aduser it needs "-otherattributes" to define the custom attribute. Which works fine if I manually add it, but wont work in my translation.(or I can't get the syntax correct) How do I properly incorporate the ability to pull custom/extension attributes straight from the csv?

    import-csv ".\newusers.csv" | Select-Object Title, Department, City, State, Office, EmployeeID,DBRMember,Manager?,Contractor,VIP,`
    @{name='name';e={($_.'First Name'+' '+$_.'Last Name')}},
    @{name='samaccountname';e={($_.'First Name'.substring(0,1)+$_.'Last Name').tolower()}},
    @{name='UserPrincipalName';e={($_.'First Name'.substring(0,1)+$_.'Last Name').toLower()+""}},
    @{name='displayname';e={$_.'First Name'+' '+$_.'Last Name'}},
    @{name='givenname';e={$_.'First Name'}},
    @{name='surname';e={$_.'Last Name'}},


    For example, this works when manually specified

    New-Aduser -ChangePasswordAtLogon $true -Enabled $true -AccountPassword $(ConvertTo-Securestring 'P@$$word' -AsPlainText -force)`
    -Description "Test User Creation By Script"`
    -HomeDrive 'h:' `
    -HomeDirectory "\\company\dfs\users\%username%"`
    -Company "Company, Inc" `
    -StreetAddress "1234 Innovation Way" `
    -PostalCode "12345"`
    #-OtherAttributes @{extensionAttribute1="TEST";extensionAttribute2= "TEST2"; extensionattribute3="Test3"; extensionattribute4="Test4"}

  • #67431

    Points: 41
    Rank: Member

    Build a hashtable from your CSV columns and pass that as the value to the OtherAttributes parameter. Tested on 2012 R2:

    #Sample CSV saved as csv1
    $users = Import-Csv c:\csv1.csv
    foreach ($user in $users) {
        $sa = $user.sAMAccountName
        $oa = @{
           adminDescription = $user.attr1
           adminDisplayName = $user.attr2
        New-ADUser -Name $sa -OtherAttributes $oa

The topic ‘Using customattributes’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort