当尝试运行脚本时,我收到以下错误消息。
错误:
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