批量分配新的 SMTP 地址和地址基于 csv 文件的带有 powershell 的新公司名称
我必须创建一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请检查以下解决方法:
CSV 文件
PowerShell 脚本
假设您尝试仅向用户添加一个 SMTP 地址,请按照以下步骤操作:
CSV 文件
PowerShell 脚本
请参阅 此处了解更多信息
Please check the below workaround:
CSV file
PowerShell Script
Suppose you are trying to add only one SMTP address to User follow the below:
CSV File
PowerShell Script
Refer here for more information