批量分配新的 SMTP 地址和地址基于 csv 文件的带有 powershell 的新公司名称

发布于 2025-01-11 15:23:54 字数 702 浏览 0 评论 0原文

我必须创建一个 Powershell 脚本,为 csv 文件的用户分配新的主 SMTP 地址。他们还需要一些其他地址。除此之外,这些用户需要更改他们的公司名称。我对所有这些东西都很陌生,试图将一些东西拼凑在一起,但行不通,这让我发疯。 :(

如果您需要更多信息,请告诉我。:)

这是我迄今为止尝试过的代码:

$Cred = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $Cred -Authentication Basic -AllowRedirection
Import-PSSession $Session
Connect-AzureAD -Confirm

#Assigning addresses & company
Import-CSV "C:\CSVPowershell\userstest.csv" | ForEach {
Set-Mailbox $_.Identity -EmailAddresses @{add= $_.MainEmailAddress}
Set-AzureADUser -ObjectId $_.Identity -CompanyName $_.Company
}


#close
Remove-PSSession $Session

I have to create a Powershell script that assigns a new main SMTP address to users of a csv file. They also need some other addresses. Besides that, those users need to change their company name. I am really new to all that stuff and tried to cobble some stuff together which wouldn´t work and it´s driving me crazy. :(

If you need more info please tell me. :)

Here is the code I´ve tried so far:

$Cred = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $Cred -Authentication Basic -AllowRedirection
Import-PSSession $Session
Connect-AzureAD -Confirm

#Assigning addresses & company
Import-CSV "C:\CSVPowershell\userstest.csv" | ForEach {
Set-Mailbox $_.Identity -EmailAddresses @{add= $_.MainEmailAddress}
Set-AzureADUser -ObjectId $_.Identity -CompanyName $_.Company
}


#close
Remove-PSSession $Session

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

会发光的星星闪亮亮i 2025-01-18 15:23:54

请检查以下解决方法:

CSV 文件

UserName, Mailform1, Mailform2 
aaa test, [email protected] , atest@companyname_Dept.com
bbb test, [email protected] , btest@companyname_Dept.com
ccc test, [email protected] , ctest@companyname_Dept.com

PowerShell 脚本

注意:在您的代码中,您缺少添加操作。您必须在脚本中使用添加/删除来执行相关操作。

    Import-CSV "C:\Users\Admin\UserEmailAddress.csv" | ForEach 
    {
        # Changing the Main Email address into your required Email.
        #Adding Multiple Email addresses (here 2 Email addresses)
        Set-Mailbox $_.UserName -EmailAddresses @{add= $_.Mailform1, $_.Mailform2}
    }

假设您尝试仅向用户添加一个 SMTP 地址,请按照以下步骤操作:

CSV 文件

UserName, Mailform1
aaa test, [email protected] 
bbb test, [email protected] 
ccc test, [email protected] 

PowerShell 脚本

    Import-CSV "C:\Users\Admin\UserEmailAddress.csv" | ForEach 
    {
        # Changing the Main Email address into your required Email.
        
        Set-Mailbox $_.UserName -EmailAddresses @{add= $_.Mailform1}
    }

请参阅 此处了解更多信息

Please check the below workaround:

CSV file

UserName, Mailform1, Mailform2 
aaa test, [email protected] , atest@companyname_Dept.com
bbb test, [email protected] , btest@companyname_Dept.com
ccc test, [email protected] , ctest@companyname_Dept.com

PowerShell Script

Note: In your code, you are missing the operation add. Either you have to use Add / Remove in your script to perform the related operation.

    Import-CSV "C:\Users\Admin\UserEmailAddress.csv" | ForEach 
    {
        # Changing the Main Email address into your required Email.
        #Adding Multiple Email addresses (here 2 Email addresses)
        Set-Mailbox $_.UserName -EmailAddresses @{add= $_.Mailform1, $_.Mailform2}
    }

Suppose you are trying to add only one SMTP address to User follow the below:

CSV File

UserName, Mailform1
aaa test, [email protected] 
bbb test, [email protected] 
ccc test, [email protected] 

PowerShell Script

    Import-CSV "C:\Users\Admin\UserEmailAddress.csv" | ForEach 
    {
        # Changing the Main Email address into your required Email.
        
        Set-Mailbox $_.UserName -EmailAddresses @{add= $_.Mailform1}
    }

Refer here for more information

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文