Home > Net >  Powershell Change Organizational Units to Title Case
Powershell Change Organizational Units to Title Case

Time:10-09

So I am trying to set the display name on my OUs to be title case. The boss says its hard to read.

foreach( $item in $ORGOU ) { Set-ADOrganizationalUnit -Identity $item.DistinguishedName -Replace -DisplayName (Get-Culture).TextInfo.ToTitleCase($item.Name.ToLower()) }


Error:
Set-ADOrganizationalUnit : Missing an argument for parameter 'Replace'. Specify a parameter of type
'System.Collections.Hashtable' and try again.
At line:1 char:89
  ... OrganizationalUnit -Identity $item.DistinguishedName -Replace -Displa ..

CodePudding user response:

The Set-AD* cmdlets offer you 2 syntaxes for doing this, you just need to choose one:

Either use the -DisplayName parameter:

Set-ADOrganizationalUnit -Identity $item.DistinguishedName -DisplayName (Get-Culture).TextInfo.ToTitleCase($item.Name.ToLower())

Or use one of the -Replace/-Add parameters, in which case you need to provide a hashtable of attribute names and values to set (this is what the error is trying to suggest):

Set-ADOrganizationalUnit -Identity $item.DistinguishedName -Replace @{description=(Get-Culture).TextInfo.ToTitleCase($item.Name.ToLower())}
  • Related