【问题标题】:Object 'user' couldn't be found on 'Domain Controller'在“域控制器”上找不到对象“用户”
【发布时间】:2020-06-19 08:21:29
【问题描述】:

我创建了 PowerShell 脚本来收集所有用户邮箱的详细信息,例如 Exchange On-Premises 上的“PrimarySmtpAddress、Identity、displayname”。我正在尝试从 powershell 运行此命令:

$UserNameInSmtpFormat = Get-Mailbox -Identity $User -ErrorAction Stop | Select PrimarySmtpAddress, Identity, displayname

此命令运行良好 (powershell.exe "c:\pstest\readUsers.ps1" 'Administrator@domain.com' 'Password' 'users.txt' 'http://Exchange/PowerShell/') 保存为 'testok.cmd'

在这个命令中我收到错误:- (powershell.exe "c:\pstest\readUsers.ps1" 'User@domain.com' 'Password' 'users.txt' 'http://Exchange/PowerShell/') 这被保存为 'testproblem.cmd'

我收到以下错误

错误:- 当我提供管理员帐户凭据时,它工作正常但是当 我正在尝试通过使用普通的“用户”凭据来收集相同的信息,然后我遇到了错误;

无法执行操作,因为在“dc.Domain.com”上找不到对象“user@domain.com”..Exception.Message

下面是脚本

( #Constant Variables 
$Office365AdminUsername = $args[0]
$Office365AdminPassword = $args[1]
$UserNamesFile = $args[2]
$connectionUri = $args[3]   
#Main
Function Main {
#Remove all existing Powershell sessions
    Get-PSSession | Remove-PSSession
#Encrypt password for transmission to Office365
    $SecureOffice365Password = ConvertTo-SecureString -AsPlainText $Office365AdminPassword -Force
#Build credentials object
    $Office365Credentials  = New-Object System.Management.Automation.PSCredential $Office365AdminUsername, $SecureOffice365Password 
Write-Host  "Credentials object created"
#Create remote Powershell session
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $connectionUri -Credential $Office365credentials -Authentication Kerberos –AllowRedirection  
Write-Host  "Remote session established"
#Check for errors
if ($Session -eq $null){
    Write-Host  "Invalid creditials"
}else{
    Write-Host  "Login success"
    #Import the session
        Import-PSSession $Session
}
try {
    Write-Host  "SMTPADDRESS"

        Foreach($User in (get-content $UserNamesFile))
        { 
            Write-Host  "mailboxIdentity : $User"
            $UserNameInSmtpFormat =Get-Mailbox -Identity $User -ErrorAction Stop | Select PrimarySmtpAddress, Identity, displayname     

            $UserNameInSmtpFormat        
    }
    Write-Host  "ENDSMTPADDRESS"
} 
catch {
   write-host "EXCEPTION"
   write-host "`r`n $_.Exception.Message"
                                }
finally {
    Exit-PSSession
    Remove-PSSession $Session
                                }
}
# Start script
. Main  
)

【问题讨论】:

  • 您可以发布更多脚本。根据您上面的内容;你在远程连接吗?或者您在本地是否有 Exchange 管理工具。如果您要远程连接,我猜用户没有适当的 RBAC 分配和/或范围。还;你具体想完成什么?您需要什么信息等...这将有助于我们提供替代解决方案等...

标签: powershell active-directory exchange-server domaincontroller


【解决方案1】:

解决方案是“角色权限”,通过将相同的权限提供给我试图从中获取邮箱详细信息的用户来解决。我已在 ECP 的“权限”选项卡中为用户分配了“邮件收件人”角色。

谢谢。

【讨论】:

    猜你喜欢
    • 2018-05-24
    • 1970-01-01
    • 2012-11-06
    • 2014-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多