Replacing attributes without removing

Welcome Forums General PowerShell Q&A Replacing attributes without removing

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

 
Participant
1 month, 2 weeks ago.

  • Author
    Posts
  • #169114

    Participant
    Topics: 6
    Replies: 11
    Points: 97
    Rank: Member

    Hello everybody, i'm having an issue with one of my script for Active directory administration.

    I want to replace something in Extensionattribute10, i'm starting with something like this:

     

    Extensionattribute10: Office365licenceE1,anotherlicence

    I want to only change the office licence and get

    Extensionattribute10: Office365licenceE3,anotherlicence

    And i need to keep everything as is after the office licence

     

    here is what i got for now:

    
    Function E1toE3 {
    foreach($user in $global:users){
    $e3 = "E3 license"
    $script:ADUserint = Get-ADUser -identity $user -server ****** -properties extensionAttribute10
    $OldAttr10 = $script:ADuserint.extensionAttribute10
    if($oldAttr10 -like "*E1 License*"){
    Set-ADUser -credential $cred -server ****** -identity $user -Replace @{extensionattribute10="E1 license"}
    $NewAttri10 = Get-ADUser -identity $user -server "******" -properties extensionAttribute10
    set-Aduser $aduserint.samaccountname -cred $cred -Server ****** -replace @{"extensionattribute10" = $newtattri10+$e3}
    Write-host "`n E1 remplacé par E3 sur le compte de $user "-BackgroundColor black -ForegroundColor green
    Write-host ""
    pause
    }
    elseif($oldAttr10 -ne "E1 license") {
    write-host "`nChoix invalide, l'utilisateur n'a pas d'e1" -BackgroundColor red -ForegroundColor white
    pause
    }
    }
    }
    
    

     

    The problem is, i just end up with :

     

    Extensionattribute10: Office365licenceE3

    everything else is removed.

    Can someone throw me an idea?

  • #169120

    Participant
    Topics: 6
    Replies: 11
    Points: 97
    Rank: Member

    i found a way, putting it here if anyone ever needs a solution

     

    
    foreach($user in $global:users){
    [string]$script:ADUserint = Get-ADUser -identity $user  -properties extensionAttribute10 | select extensionattribute10
    }
    
    $script:ADUserint| foreach {
    $items = $_.split(",")
    }
    set-Aduser $user -cred $cred  -replace @{"extensionattribute10" = "license,"+$items[1]}
    Get-ADUser  $global:users -properties extensionAttribute10
    
    

You must be logged in to reply to this topic.