Share via


Appending line to info attribute with Powershell

Question

Sunday, July 21, 2013 6:52 PM

Have any of you had to append text to the info attribute in Active with the MS cmdlets? It is super easy with Quest AD cmdlets. I am doing Set-Aduser -identity $CN -add @{"info"=$Text} . It complains that the attribute can only have on value. I have tried:

$CurrentNotes =  Get-ADUser -Identity $CN  -Properties Info

$NewNote = (Get-Date -Format g) + ' - ' + $Text + '
' + $CurrentNotes.Info

    if ($CurrentNotes.Length -gt 1024)
    {
        $NewNote = $CurrentNotes.SubString(0,1024)
    }
        
    Set-ADUser -Identity $CN -Add @{'info'=$NewNote}

Thanks for any suggestions
 

All replies (1)

Sunday, July 21, 2013 8:32 PM âś…Answered | 1 vote

Since you're getting the current value, appending the new details and writing that back to AD you should use -Replace rather than -Add so you end up with :

Set-ADUser -Identity $CN -Replace @{'info'=$NewNote}

Full details of Set-ADUser are here http://technet.microsoft.com/en-us/library/ee617215.aspx not most importantly is the fact that for each of them you can use -Replace, -Clear and -Remove parameters as well as -Add.