添加成员:无法添加名为“”的成员,因为已存在具有该名称的成员
Add-Member : Cannot add a member with the name "" because a member with that name already exists
尝试 运行 脚本时,我收到以下错误消息。
错误:
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:\tmp\users.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:\tmp\users.csv" -NoTypeInformation -Encoding UTF8
如果您想进一步 trim 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:\tmp\users.csv" -NoTypeInformation -Encoding UTF8
尝试 运行 脚本时,我收到以下错误消息。
错误:
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:\tmp\users.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:\tmp\users.csv" -NoTypeInformation -Encoding UTF8
如果您想进一步 trim 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:\tmp\users.csv" -NoTypeInformation -Encoding UTF8