Powershell 将组织单位更改为标题大小写

Powershell Change Organizational Units to Title Case

所以我试图将我的 OU 上的显示名称设置为首字母大写。老板说很难看

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 ..

Set-AD* cmdlet 为您提供了 2 种语法来执行此操作,您只需选择 一个:

要么使用-DisplayName参数:

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

或使用 -Replace/-Add 参数之一,在这种情况下,您需要提供要设置的属性名称和值的哈希表(这就是错误试图提出的建议) :

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