我正在编写一个脚本,它将从CSV文件中更新Exchange邮箱属性。当我运行我的脚本时,我会得到一个'A参数不能找到与参数名称‘title’相匹配的参数。“错误。任何想法。我正在尝试更改Exchange组织选项卡中的title属性。
我知道错误消息意味着什么,但我在任何地方都找不到用于更改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发布于 2020-06-26 12:01:41
Set-User的params不包含-Identity,因此PowerShell不知道应该将标题设置给谁。你需要加一句:
$SetParams =
@{
Identity = $User.Username
Title = $User.Title
}确保Username包含有效的标识,这样就可以根据它来确定用户。
https://stackoverflow.com/questions/62478206
复制相似问题