Removing part of the Notes field

There will be occasions when you need to remove part of the Notes field

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

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

Create a here-string with the content you want to remove.

In all cases get the attribute value and use the String Replace() method to replace the unwanted text with an empty string “”

In the case of the script we substitute the result into a here-string for posting back.  Also notice how you have to use the ToString() method

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

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s