gpt4 book ai didi

azure - 通过 AzureAD 的 powershell 更新用户电子邮件地址

转载 作者:行者123 更新时间:2023-12-03 02:43:05 25 4
gpt4 key购买 nike

我想知道是否有人可以提供帮助,我们组织中有一些用户使用大写电子邮件地址,某些应用程序无法识别这一点并失败。我开发了下面的脚本来将用户 UPN 和显示名称更改为小写,但这不会更改他们的电子邮件地址。我不想创建新邮箱,因为有数百个用户的格式不正确。如果有人能指出我正确的方向,那将是一个很大的帮助。

#Install-module AzureAD
#Connect-AzureAD
$Users = Get-azureADUser -filter "userPrincipalName eq '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7e2b0d1b0c4f3e33073a11131f1710501d1113" rel="noreferrer noopener nofollow">[email protected]</a>'"
$ErrorActionPreference = 'Stop'
$OutputObj = New-Object -TypeName PSobject
$OutputObj1 = New-Object -TypeName PSobject
$SuccessOutput = @()
$ErrorOutput = @()
$Case = "toLower"
Function ChangeToLowerCase{

Try{
foreach ($user in $users) {
$user | Set-AzureADUser -userPrincipalName $user.userPrincipalName.$Case()
$user | Set-AzureADUser -identity $user.SipProxyAddress.$Case()


#$User | Select-Object DisplayName, userPrincipalName,Mail
$OutputObj | Add-Member -memberType NoteProperty -name "Display Name" -value $($user.DisplayName)
$OutputObj | Add-Member -memberType NoteProperty -name "UPN" -value $($user.userPrincipalName)
$OutputObj | Add-Member -memberType NoteProperty -name "Email Address" -value $($user.Mail)
$SuccessOutput +=$OutputObj
$SuccessOutput | Export-csv "C:\Temp\Powershell\Completed\UPN Changes.csv" -NoTypeInformation -NoClobber -Append
}
}
Catch{
$OutputObj1 | Add-Member -memberType NoteProperty -name "Display Name" -value $($user.DisplayName)
$OutputObj1 | Add-Member -memberType NoteProperty -name "Error Message" -value $($_.Exception.Message)
$ErrorOutput +=$OutputObj1
$ErrorOutput | Export-csv "C:\Temp\Powershell\Errors\UPN Changes Error.csv" -NoTypeInformation -NoClobber -Append
}
}
ChangeToLowerCase

我正在查看 Set-AzureAduser 属性,但是我无法更改此变量中的邮件属性。

最佳答案

很好,在添加大写 W 的域后,我遇到了同样的问题。它不会更改电子邮件地址,因为它不区分大小写。

我创建这个是为了解决这个问题:

function ConvertTo-LowerW
{

foreach ($Recipient in $Recipients)
{
"1"
$Recipient.PrimarySmtpAddress

$SplitEmail = $Recipient.PrimarySmtpAddress.Split('@')
$BeforeA = $SplitEmail | Select-Object -First 1
$AfterA = ($SplitEmail | Select-Object -Last 1).ToLower()
$NewPrimarySmtpAddress = $BeforeA + '@' + $AfterA

$NewPrimarySmtpAddress

switch ($Recipient.RecipientType)
{

'UserMailbox'
{
try
{
$Addresses = (Get-Mailbox -Identity $Recipient.PrimarySmtpAddress -ErrorAction Stop).EmailAddresses
$Addresses = $Addresses.Replace("SMTP:$($recipient.PrimarySmtpAddress)", "")

Set-Mailbox -ErrorAction Stop `
-Identity $Recipient.PrimarySmtpAddress `
-EmailAddresses $NewPrimarySmtpAddress

if ($Addresses.Length -ne 0)
{
foreach ($Address in ($Addresses | Where-Object { $_.Length -ne 0 }) )
{
$Address
if ($Address.Length -ne 0 )
{
Set-Mailbox -ErrorAction Stop `
-Identity $Recipient.PrimarySmtpAddress `
-EmailAddresses @{add = "$Address" }
}
}
}
}

Catch
{
$ErrorList.Add($Recipient.PrimarySmtpAddress)
$ErrorList.Add($_.Exception.Message)

}

}

'MailUniversalDistributionGroup'
{
try
{
$Addresses = (Get-DistributionGroup -Identity $Recipient.PrimarySmtpAddress -ErrorAction Stop).EmailAddresses
$Addresses = $Addresses.Replace("SMTP:$($recipient.PrimarySmtpAddress)", "")

Set-DistributionGroup -ErrorAction Stop `
-Identity $Recipient.PrimarySmtpAddress `
-EmailAddresses $NewPrimarySmtpAddress

if ($Addresses.Length -ne 0)
{
foreach ($Address in ($Addresses | Where-Object { $Addresses.Length -ne 0 }))
{
if ($Address.Length -ne 0 )
{
Set-DistributionGroup -ErrorAction Stop `
-Identity $Recipient.PrimarySmtpAddress `
-EmailAddresses @{add = "$Address" }
}
}
}
}
catch
{
$ErrorList.Add($Recipient.PrimarySmtpAddress)
$ErrorList.Add($_.Exception.Message)
}

}

'DynamicDistributionGroup'
{
try
{
$Addresses = (Get-DynamicDistributionGroup -Identity $Recipient.PrimarySmtpAddress -ErrorAction Stop).EmailAddresses
$Addresses = $Addresses.Replace("SMTP:$($recipient.PrimarySmtpAddress)", "")

Set-DynamicDistributionGroup -ErrorAction Stop `
-Identity $Recipient.PrimarySmtpAddress `
-EmailAddresses $NewPrimarySmtpAddress

if ($Addresses.Length -ne 0)
{
foreach ($Address in ($Addresses | Where-Object { $Addresses.Length -ne 0 }))
{
$Address
if ($Address.Length -ne 0 )
{
Set-DynamicDistributionGroup -ErrorAction Stop `
-Identity $Recipient.PrimarySmtpAddress `
-EmailAddresses @{add = "$Address" }
}
}
}
}
catch
{
$ErrorList.Add($Recipient.PrimarySmtpAddress)
$ErrorList.Add($_.Exception.Message)
}
}

Default
{
try
{

$Recipient.RecipientType
$Recipient.RecipientTypeDetails
'User has an unrecognized Recipienttype'

Send-Email `
-To $to `
-Body 'Test' `
-Subject 'User has an unrecognized Recipienttype'
}
catch
{
$ErrorList += "$($($Recipient).PrimarySmtpAddress) has an unrecognized RecipientType $($($Recipient).Recipienttype)"
$ErrorList.Add($Recipient.PrimarySmtpAddress)
$ErrorList.Add($_.Exception.Message)
}
}
}
}
}

我会看看是否可以在 bwit.blog 上创建博客文章关于这一点。

关于azure - 通过 AzureAD 的 powershell 更新用户电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60149643/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com