Copying the ModelID's Attributes to an Existing Users

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of BIJO DEV BIJO DEV 3 weeks, 6 days ago.

  • Author
  • #54758
    Profile photo of BIJO DEV

    Hi All,

    I am trying to run a script in which there are bunch of users in a csv file (those are existing users). I need to make some changes to all those user's attributes with separate bunch of model ID.
    1) Copy the office details and the script path of MODEL ID to the existing users(which are in CSV).
    2) Need to add the ADgroup which are there in model id to the existing users.

    I was able to Add the AD group for all those 75 users, but the latter part like the model's id office details are not getting copied. And some of the model ID are not present in Active directory.

    I don't want screen to get filled up the error message and all want the opposite users list script may also execute.

    Any help would be grateful.

  • #54760
    Profile photo of Rob Simmers
    Rob Simmers

    Can you provide the CSV example? Are you trying to take what is in the csv and copy it to Active Directory attributes? I'm not sure what you mean by model ID. If you mean like a Victoria's Secret model, then I will need to come onsite to do a full discovery, meet & greet and tour. 🙂

  • #54761
    Profile photo of BIJO DEV

    Hello Rob,
    Thanks for rplying.

    This is how my CSV looks like (Here the model ID is used as a clone body to copy the basic details)

    modelID samaccountname Givenname Surname DisplayName
    testps2 testps8 test ps8 test ps8
    hello1 testps9 test ps9 test ps9
    testps20 testps10 test ps10 test ps10
    testps11 test ps11 test ps11

    This is script – I first tried with the instance one but it didn't worked out with the "set-aduser"
    "Under the column modelID " you could see 3 ID's out of which 2 exist and 1 doesn't exist and the 4th item I haven't taken just to check whether the script runs without a modelID or not"

    $importlist = read-host -prompt "provide the CSV PATH which needs to be imported"
    $users=import-csv -Path $importlist
    foreach($user in $users)
    $ErrorActionPreference = "SilentlyContinue"
    if($user.modelid -ne "$null")
    $modelID = Get-ADUser -identity $user.modelID -Properties office, State, country, scriptpath, company
    $modelID.UserPrincipalName = $null
    set-aduser $user.samaccountname -Office $ -Company $ -ScriptPath $modelID.scriptpath -State $modelID.state -Country $ -ErrorAction SilentlyContinue -ErrorVariable invalidmodelid
    $EmailAddress = ($user.GivenName+"_"+$user.SurName+"")
    $mailnickname = ($user.GivenName+"_"+$user.SurName)

    Set-ADuser $user.samaccountname -EmailAddress $EmailAddress -Description $user.Newdescription -OfficePhone $user.phonenumber
    Set-ADUser $user.samaccountname -replace @{mailnickname=$mailnickname}
    set-aduser $user.samaccountname -replace @{targetaddress=$EmailAddress;msExchHideFromAddressLists=$false}

    Set-ADuser -Identity $user.samaccountname -add @{proxyaddresses="SMTP:"+$EmailAddress}
    Set-ADuser -Identity $user.samaccountname -add @{proxyaddresses="smtp:"+$mailnickname+""}
    Set-ADuser -Identity $user.samaccountname -Add @{proxyaddresses="sip:"+$EmailAddress}

  • #54762
    Profile photo of BIJO DEV

    This is the correct CSV file which I need to import

    modelID samaccountname Givenname Surname DisplayName
    HD1 testps01 test ps8 test ps8
    HD2 testps02 test ps9 test ps9
    HD5 testps10 test ps10 test ps10
    ***** testps11 test ps11 test ps11

    HD1 and HD2 are valid ID present in active directory , HD5 is not valid, the last I have taken as null value.

You must be logged in to reply to this topic.