# Problem with command arguments

**URL:** <https://forums.powershell.org/t/problem-with-command-arguments/5250>\
**Category:** PowerShell Help\
**Created:** [November 22, 2015, 9:26pm UTC](https://forums.powershell.org/t/problem-with-command-arguments/5250 "2015-11-22T21:26:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexander-wolfshohl](https://avatars.discourse-cdn.com/v4/letter/a/f0a364/32.png) [@alexander-wolfshohl](https://forums.powershell.org/u/alexander-wolfshohl)\
**Post date:** [November 22, 2015, 9:26pm UTC](https://forums.powershell.org/t/problem-with-command-arguments/5250/1 "2015-11-22T21:26:51Z")

</div>

Hey folks,  
i have a problem with powershell script:  
I would like to clear some User attributes with the following command:  
Set-ADUser -Identity $samaccountname -Clear $clear

The $clear came from following if construct:  
if (!($txtbox\_city.“Text” -like “”)) { $replace[‘l’] = $txtbox\_city.“Text” } else { $clear = “‘l’,”}  
if (!($txtbox\_country.“Text” -like “”)) { $replace[‘co’] = “Germany” } # else { $clear += “‘co’,” }  
if (!($txtbox\_cc.Text -like “”)) {$replace[‘countryCode’] = $codepage }  
if (!($txtbox\_abt3.“Text” -like “”)) { $replace[‘o’] = $txtbox\_abt3.“Text” } else { $clear += “‘o’,” }  
if (!($txtbox\_dn.“Text” -like “”)) { $replace[‘Displayname’] = $txtbox\_dn.“Text” } else { $clear += “‘DisplayName’,” }  
if (!($txtbox\_amt.“Text” -like “”)) { $replace[‘Department’] = $txtbox\_amt.“Text” } else { $clear += “‘Department’,” }  
if (!($txtbox\_desc.“Text” -like “”)) { $replace[‘Description’] = $txtbox\_desc.“Text” } else {$clear += “‘Description’,” }  
if (!($txtbox\_referat.“Text” -like “”)) { $replace[‘Division’] = $txtbox\_referat.“Text” } else { $clear += “‘Division’,” }  
if (!($txtbox\_eid.“Text” -like “”)) { $replace[‘employeeID’] = $txtbox\_eid.“Text” } else { $clear += “‘employeeID’,” }  
if (!($txtbox\_pnr.“Text” -like “”)) { $replace[‘EmployeeNumber’] = $txtbox\_pnr.“Text” } else { $clear += “‘EmployeeNumber’,” }

When i do this i became the error:  
System.ArgumentExceptionThe specified directory service attribute or value does not exist  
Parameter name: ‘l’,‘o’,‘Description’,‘Division’,‘employeeID’,‘EmployeeNumber’,‘EmployeeType’,‘facsimileTelephoneNumber’

When I do it in the powershell the same command, its working fine.

What can i do?

Thx

---

<div class="post-metadata">

**Author:** ![noam-lesnik](https://avatars.discourse-cdn.com/v4/letter/n/aeb1de/32.png) [@noam-lesnik](https://forums.powershell.org/u/noam-lesnik)\
**Post date:** [November 23, 2015, 7:08pm UTC](https://forums.powershell.org/t/problem-with-command-arguments/5250/2 "2015-11-23T19:08:39Z")

</div>

Hi,

The Clear parameter accepts string with is an array of strings, what you are doing is creating a single string and separating the attributes with ‘,’ .

To fix the code you need to initialize the $clear variable like this:

```
$clear = @()
```

This will create it as an empty array.

To add the desired attributes to $clear:

```
$clear += 'l'
```

Please lets us know if it works.

---

<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:44pm UTC](https://forums.powershell.org/t/problem-with-command-arguments/5250/3 "2024-05-16T20:44:22Z")

</div>


