Monthly Archive


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

Leave a Reply