powershell - Rename surname and givenName of contact object -
can please tell me how can rename sn
, givenname
of contact object in active directory?
this how query data in contacts ou:
get-adobject -filter {(objectclass -eq "contact") -and (givenname -like "*myname*") } -properties sn, givenname -searchbase "ou=contacts,dc=domain,dc=name"
from microsoft:
to modify given name, surname , other name of user, use set-aduser cmdlet
my goal modify values of both properties because have text in lowercase , hoping use like:
$textinfo = (get-culture).textinfo $textinfo.totitlecase("one-two three") desired output: one-two 3
to capital letter each word.
some examples great.
if know of gui-tool need please share well.
to change attributes on contact ad object need use set-adoject
cmdlet, -replace
parameter. set-aduser
set attributes of ad object of type user.
the following code take full name
of contact object, search in ad , change givenname
, sn
, displayname
title case.
i have added displayname
field not automatically update when change first , last name, can delete part if it's not needed.
$fullname = "my name" $contact = get-adobject -filter {(objectclass -eq "contact") -and (name -like $fullname)} -properties * -searchbase "ou=contacts,dc=domain,dc=name" $textinfo = (get-culture).textinfo $givennametotitlecase = $textinfo.totitlecase(($contact.givenname).tolower()) $sntotitlecase = $textinfo.totitlecase(($contact.sn).tolower()) $displaynametotitlecase = $textinfo.totitlecase(($contact.displayname).tolower()) $contact | set-adobject -replace @{givenname=$givennametotitlecase;` sn=$sntotitlecase;` displayname=$displaynametotitlecase;}
Comments
Post a Comment