Add to Notes field

You may need to add extra information to the notes field

$ou = "OU=BlogTests,DC=Manticore,DC=org"            
$extra = @"

Just a bit more info
$name = "UserA"            
$p = Get-ADUser -Identity $name -Properties *            
$note = $ + $extra            
Set-ADUser -Identity $name -Replace @{info = $note}            
"`nAD provider"            
$name = "UserB"            
$dn = "cn=$name,$ou"            
$p = Get-ItemProperty -Path AD:\$dn  -Name info             
$note = $ + $extra            
Set-ItemProperty -Path AD:\$dn  -Name info -Value $note  -Force            
$name = "UserC"            
$p = Get-QADUser -Identity $name -IncludeAllProperties            
$note = $ + $extra            
Set-QADUser  -Identity $name -ObjectAttributes @{info=$note}            
$name = "UserD"            
$dn = "cn=$name,$ou"            
$user = [adsi]"LDAP://$dn"            
$note = @"

$ = $note            

The Microsoft & Quest cmdlets together with the provider all work in the same way. Get the current attribute value, use string concatenation to add the extra info and write back to AD

The script is slightly different in that we have to create a new here-string by substituting the current value and the new info. The combined data can be written back to AD.  If you try to  use ordinary string concatenation you will get a “The specified directory service attribute or value already exists.” error.

This entry was posted in PowerShell and Active Directory. Bookmark the permalink.

One Response to Add to Notes field

  1. Sebastian says:

    Thanks, you saved my life!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s