在 'Domain Controller' 上找不到对象 'user'

Object 'user' couldn't be found on 'Domain Controller'

我创建了 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'

我收到以下错误

错误:- 当我给管理员帐户凭据时,它工作正常但是当 我试图通过使用 Normal 'User' 凭据来收集相同的信息,然后我遇到了以下错误;

The operation couldn't be performed because object 'user@domain.com' couldn't be found on 'dc.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  
)

解决方案是 "Role Permission rights",通过向我试图从中获取邮箱详细信息的用户提供相同的解决方案。我已从 ECP 中的“权限”选项卡将 "Mail Recipient" 角色分配给用户。

谢谢。