admin管理员组

文章数量:1332339

I am trying to run a PowerShell script to change all UPNs in a specific OU to lowercase, but I am not having any success. Based on some previous posts and using the same command I use to change other attributes successfully, I am trying the following:

Get-ADUser -Filter * -SearchBase "OU=[REDACTED]" 
    | Set-ADUser -replace @{userPrincipalName=userPrincipalName.ToLower}

But when I run this I am getting an error

'userPrincipalName.ToLower' is not recognized

I have also tried adding () to the end of ToLower, but with the same result.

Any suggestions would be greatly appreciated. Thank you for your time.

I am trying to run a PowerShell script to change all UPNs in a specific OU to lowercase, but I am not having any success. Based on some previous posts and using the same command I use to change other attributes successfully, I am trying the following:

Get-ADUser -Filter * -SearchBase "OU=[REDACTED]" 
    | Set-ADUser -replace @{userPrincipalName=userPrincipalName.ToLower}

But when I run this I am getting an error

'userPrincipalName.ToLower' is not recognized

I have also tried adding () to the end of ToLower, but with the same result.

Any suggestions would be greatly appreciated. Thank you for your time.

Share Improve this question edited Nov 20, 2024 at 20:33 marc_s 756k184 gold badges1.4k silver badges1.5k bronze badges asked Nov 20, 2024 at 20:17 AA27CXPAA27CXP 135 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You're missing a loop in your code to get the pipped user's UserPrincipalName, add ForEach-Object and reference it via $_.UserPrincipalName, then you can .ToLower() it:

Get-ADUser -Filter * -SearchBase 'OU=[REDACTED]' | ForEach-Object {
    Set-ADUser -Identity $_ -UserPrincipalName $_.UserPrincipalName.ToLower()
}

本文标签: active directoryHaving trouble making UserPrincipalName all lowercase in PowershellStack Overflow