添加成员:无法添加名称为 " " 的成员,因为具有该名称的成员已存在

  • 本文关键字:成员 添加 存在 因为 powershell
  • 更新时间 :
  • 英文 :


当尝试运行脚本时,我收到以下错误消息。

错误:

Add-Member : Cannot add a member with the name "CAllerID*" because a member with that name already exists. To overwrite the member anyway, add the Force parameter to 
your command.

脚本:

$output = Get-ADUser -Identity user -Properties givenName, sn, displayname, samaccountname, title
$output | Add-Member -membertype noteproperty -name "CAllerID*" -value $null | Export-CSV -Path "c:tmpusers.csv" -NoTypeInformation -Encoding UTF8

-Force-PassThru添加到Add-Member调用:

  • -Force确保覆盖任何现有的冲突属性
  • -PassThru使Add-Member输出修改后的输入对象
$output | Add-Member -MemberType NoteProperty -Name "CAllerID*" -Value $null -Force -PassThru | Export-CSV -Path "c:tmpusers.csv" -NoTypeInformation -Encoding UTF8

如果要进一步修剪Get-ADUser返回的属性集,请使用Select-Object:

$output | Select-Object -Property givenName,sn,displayName,SAMAccountName,Title | Add-Member -MemberType NoteProperty -Name "CAllerID*" -Value $null -Force -PassThru | Export-CSV -Path "c:tmpusers.csv" -NoTypeInformation -Encoding UTF8

最新更新