When attempting to run script then I got the following the error message.
Error :
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.
Script :
$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
CodePudding user response:
Add -Force
and -PassThru
to the Add-Member
call:
-Force
ensures any existing conflicting properties are overwritten-PassThru
causesAdd-Member
to output the modified input object
$output | Add-Member -MemberType NoteProperty -Name "CAllerID*" -Value $null -Force -PassThru | Export-CSV -Path "c:\tmp\users.csv" -NoTypeInformation -Encoding UTF8
If you want to further trim the property set returned by Get-ADUser
, use 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