So this comes up a lot. You have a field in AD but your script will not modify it. You need to change the field attribute to the new entry but the logical commands (like -delete or $Null) don’t work and just return errors.
These special fields require a combo command request which combines get-aduser with set-aduser. Then you simply enter a -clear command and you’re all done.
I don’t know why this is such a hard thing to find a solution for on the internet. Most of the sites I visited had overcomplicated lines of code for this simple command.
Here is the entire command in use to clear the (email) field in AD.
get-aduser samname | set-aduser -clear mail
Example: get-aduser bsmith | set-aduser -clear mail

The “samname” is the account logon name. Example: bsmith
Here is a pretty decent list of all the field names:
accountExpires |
accountNameHistory |
aCSPolicyName |
adminCount |
adminDescription |
adminDisplayName |
allowedAttributes |
allowedAttributesEffective |
allowedChildClasses |
allowedChildClassesEffective |
altSecurityIdentities |
assistant |
badPasswordTime |
badPwdCount |
bridgeheadServerListBL |
c |
canonicalName |
cn |
co |
codePage |
comment |
company |
controlAccessRights |
countryCode |
createTimeStamp |
dBCSPwd |
defaultClassStore |
department |
description |
desktopProfile |
destinationIndicator |
directReports |
displayName |
displayNamePrintable |
distinguishedName |
division |
dSASignature |
dSCorePropagationData |
dynamicLDAPServer |
employeeID |
extensionName |
facsimileTelephoneNumber |
flags |
fromEntry |
frsComputerReferenceBL |
fRSMemberReferenceBL |
fSMORoleOwner |
garbageCollPeriod |
generationQualifier |
givenName |
groupMembershipSAM |
groupPriority |
groupsToIgnore |
homeDirectory |
homeDrive |
homePhone |
homePostalAddress |
info |
initials |
instanceType |
internationalISDNNumber |
ipPhone |
isCriticalSystemObject |
isDeleted |
isPrivilegeHolder |
l |
lastKnownParent |
lastLogoff |
lastLogon |
legacyExchangeDN |
lmPwdHistory |
localeID |
lockoutTime |
logonCount |
logonHours |
logonWorkstation |
managedObjects |
manager |
masteredBy |
maxStorage |
memberOf |
mhsORAddress |
middleName |
mobile |
modifyTimeStamp |
mS-DS-ConsistencyChildCount |
mS-DS-ConsistencyGuid |
mS-DS-CreatorSID |
mSMQDigests |
mSMQDigestsMig |
mSMQSignCertificates |
mSMQSignCertificatesMig |
msNPAllowDialin |
msNPCallingStationID |
msNPSavedCallingStationID |
msRADIUSCallbackNumber |
msRADIUSFramedIPAddress |
msRADIUSFramedRoute |
msRADIUSServiceType |
msRASSavedCallbackNumber |
msRASSavedFramedIPAddress |
msRASSavedFramedRoute |
name |
netbootSCPBL |
networkAddress |
nonSecurityMemberBL |
ntPwdHistory |
nTSecurityDescriptor |
o |
objectCategory |
objectClass |
objectGUID |
objectSid |
objectVersion |
operatorCount |
otherFacsimileTelephoneNumber |
otherHomePhone |
otherIpPhone |
otherLoginWorkstations |
otherMailbox |
otherMobile |
otherPager |
otherTelephone |
otherWellKnownObjects |
ou |
pager |
partialAttributeDeletionList |
partialAttributeSet |
personalTitle |
physicalDeliveryOfficeName |
possibleInferiors |
postalAddress |
postalCode |
postOfficeBox |
preferredDeliveryMethod |
preferredOU |
primaryGroupID |
primaryInternationalISDNNumber |
primaryTelexNumber |
profilePath |
proxiedObjectName |
proxyAddresses |
pwdLastSet |
queryPolicyBL |
registeredAddress |
replPropertyMetaData |
replUpToDateVector |
repsFrom |
repsTo |
revision |
rid |
sAMAccountName |
sAMAccountType |
scriptPath |
sDRightsEffective |
securityIdentifier |
seeAlso |
serverReferenceBL |
servicePrincipalName |
showInAddressBook |
showInAdvancedViewOnly |
sIDHistory |
siteObjectBL |
sn |
st |
street |
streetAddress |
subRefs |
subSchemaSubEntry |
supplementalCredentials |
systemFlags |
telephoneNumber |
teletexTerminalIdentifier |
telexNumber |
terminalServer |
textEncodedORAddress |
thumbnailLogo |
thumbnailPhoto |
title |
tokenGroups |
tokenGroupsGlobalAndUniversal |
tokenGroupsNoGCAcceptable |
unicodePwd |
url |
userAccountControl |
userCert |
userCertificate |
userParameters |
userPassword |
userPrincipalName |
userSharedFolder |
userSharedFolderOther |
userSMIMECertificate |
userWorkstations |
uSNChanged |
uSNCreated |
uSNDSALastObjRemoved |
USNIntersite |
uSNLastObjRem |
uSNSource |
wbemPath |
wellKnownObjects |
whenChanged |
whenCreated |
wWWHomePage |
x121Address |
Thanks I’ll save this
LikeLiked by 2 people