# Script to Clear AD Attributes

**URL:** <https://forums.powershell.org/t/script-to-clear-ad-attributes/3394>\
**Category:** PowerShell Help\
**Created:** [November 10, 2014, 1:40am UTC](https://forums.powershell.org/t/script-to-clear-ad-attributes/3394 "2014-11-10T01:40:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![allen-rohl](https://avatars.discourse-cdn.com/v4/letter/a/df788c/32.png) [@allen-rohl](https://forums.powershell.org/u/allen-rohl)\
**Post date:** [November 10, 2014, 1:40am UTC](https://forums.powershell.org/t/script-to-clear-ad-attributes/3394/1 "2014-11-10T01:40:28Z")

</div>

Hello,

I have the following lines in a powershell script to search for the # and then remove it from the AD record (thus setting the field to in ADSI Edit):

$iUsers1 = Get-QADUser -SearchRoot $OU -SizeLimit 0 -objectAttributes @{extensionAttribute13 = “#”} | Set-QADUser -objectAttributes @{extensionAttribute13=@{Clear=@()}}  
$iUsers2 = Get-QADUser -SearchRoot $OU -SizeLimit 0 -homePhone = “#” | Set-QADUser -homePhone = $null

The extensionAttribute13 field is successfully cleared. The -homePhone field is not and I receive the following error:

Set-QADUser : Cannot validate argument on parameter ‘Identity’. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.  
At C:\Remove\_hash\_2.ps1:15 char:84

- $iUsers13 = Get-QADUser -SearchRoot $OU -SizeLimit 0 -homePhone = “#” | Set-QADUser \<\<\<\< -homePhone = $null
  - CategoryInfo : InvalidData: (🙂 [Set-QADUser], ParameterBindingValidationException
  - FullyQualifiedErrorId : ParameterArgumentValidationError,Quest.ActiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.SetUserCmdlet

To make sure I had the correct syntax, I did the following from the ActiveRoles AD shell:

Set-QADUser 'username' -homePhone $null

And that worked.

I would appreciate any guidance with this.

Thank you.

---

<div class="post-metadata">

**Author:** ![matt-mcnabb](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-mcnabb](https://forums.powershell.org/u/matt-mcnabb)\
**Post date:** [November 10, 2014, 4:45am UTC](https://forums.powershell.org/t/script-to-clear-ad-attributes/3394/2 "2014-11-10T04:45:14Z")

</div>

A couple of things:

If you read the error closely you’ll see exactly what the problem is. If you just run the first half of your pipeline you’ll probably see that no users are returned. This means that the Set-QADUser does not receive any objects to act on. I’m not very familiar with the Quest cmdlets but I don’t believe your argument to the -HomePhone parameter of Get-QADUser will work since you are using the ‘=’ operator which is for assignments. From their documentation it looks like you could specify -HomePhone ‘#\*’.

Also, why are you saving the results of the Set-QADUser cmdlet to a variable? This isn’t really necessary, but I don’t think that’s your problem.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [November 10, 2014, 4:49am UTC](https://forums.powershell.org/t/script-to-clear-ad-attributes/3394/3 "2014-11-10T04:49:01Z")

</div>

The problem is an extra = sign in your code, which you didn’t type when you tried the command at a shell:

```
Set-QADUser -homePhone = $null

# Should just be

Set-QADUser -homePhone $null
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:46pm UTC](https://forums.powershell.org/t/script-to-clear-ad-attributes/3394/4 "2024-05-16T20:46:47Z")

</div>

Closed on May 16, 2024, 8:46pm UTC


