Set-User: 使用 Connect-ExchangeOnline 找不到与参数名称 'Title' 匹配的参数

Set-User: A parameter cannot be found that matches parameter name 'Title' using Connect-ExchangeOnline

我正在编写一个脚本,用于从 CSV 文件更新 Exchange 邮箱属性。当我 运行 我的脚本时,我得到一个“找不到与参数名称 'Title' 匹配的参数。”错误。任何想法。我正在尝试更改组织选项卡中的标题 属性在交换中。

我知道错误消息的含义,但我无法在任何地方找到更改标题属性的语法。

脚本:

# Updates AD user attributes from CSV file


$Credential = Get-Credential
Connect-ExchangeOnline -Credential $Credential

# Load data from file.csv
$ADUsers = Import-csv file_path

# Count variable for number of users update
$count = 0

# Go through each row that has user data in the CSV we just imported 
ForEach($User in $ADUsers)
{
    # Ppopulate hash table for Get-ADUser splatting:
    $GetParams =
    @{
        Identity     = $User.Username
    }

    # Initialize hash table for Set-ADUser splatting:
    $SetParams =
    @{
        Title        = $User.Title  
    }

    # Check to see if the user already exists in AD. If they do, we update.
    if ( Get-EXORecipient @GetParams)
    {
         # Set User attributes
         Set-User @SetParams -WhatIf

         # Print that the user was updated 
         Write-Host -ForegroundColor Yellow "$User - User attributes have been updated." 

         # Update Count
         $count += 1    
     }
}

# Print the number of updated users
Write-Host $count "Users have been updated" -ForegroundColor Green

错误信息:

A parameter cannot be found that matches parameter name 'Title'.
    + CategoryInfo          : InvalidArgument: (:) [Set-Mailbox], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Set-Mailbox
    + PSComputerName        : outlook.office365.com

Set-User 的参数不包含 -Identity,因此 PowerShell 不知道标题应该设置给谁。您需要添加它:

$SetParams =
@{
    Identity     = $User.Username
    Title        = $User.Title  
}

确保Username包含有效身份,以便根据它确定用户。