'Add-Member : Cannot add a member with the name "" because a member with that name already exists
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
Solution 1:[1]
Add -Force and -PassThru to the Add-Member call:
-Forceensures any existing conflicting properties are overwritten-PassThrucausesAdd-Memberto 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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
