当我在下面运行命令时,它可以预测
get-mailbox -identity xxx.xxx@domain .com
当我尝试在脚本中运行相同的命令时,它仍然无法在域控制器上找到错误
$ users = Import-Csv“C:\ Users \ xx \ Documents \ CSV \ PORB.csv”foreach ($ users in $ users){ $ Recipients = Get-Mailbox -Identity $ user.users [array] $ AllEmailAddresses = $ Recipient.EmailAddresses [array] $ NoX500Addresses = $ Recipient.EmailAddresses |哪里{$ _ - 不喜欢“X500:*”} Set-Mailbox -Identity $ Recipient.Identity -EmailAddresses $ NoX500Addresses
我得到错误:Get-Mailbox:无法执行操作,因为在域控制器上找不到对象'd.j@domain.com' 'XXX.aaa.bbbb.ccc.net'。 在行:5 char:19 + $ Recipients = Get-Mailbox -Identity $ user.users}
**我不确定我做错了什么我还包括** $AdminSessionADSettings.ViewEntireForest = $true
答案 0 :(得分:0)
在网络上找到另一个脚本以获取域列表并对列表中的每个域执行操作
$ objForest = [System.DirectoryServices.ActiveDirectory.Forest] :: GetCurrentForest() $ DomainList = @($ objForest.Domains | Select-Object Name)$ Domains = $ DomainList | foreach {$ _。姓名}
对每个域采取行动
foreach($ Domain in($ Domains)){$ users = Import-Csv" C:\ Users \ ramer \ Documents \ CSV \ PORB.csv" foreach($ user in $ users){$ Recipients = Get-Mailbox -Identity $ user.users [array] $ AllEmailAddresses = $ Recipient.EmailAddresses [array] $ NoX500Addresses = $ Recipient.EmailAddresses |哪里{$ _ -notlike" X500:*"} Set-Mailbox -Identity $ Recipient.Identity -EmailAddresses $ NoX500Addresses}