# Wildcards..

**URL:** <https://forums.powershell.org/t/wildcards/2853>\
**Category:** PowerShell Help\
**Created:** [July 18, 2014, 11:57pm UTC](https://forums.powershell.org/t/wildcards/2853 "2014-07-18T23:57:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![adam-nichols](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@adam-nichols](https://forums.powershell.org/u/adam-nichols)\
**Post date:** [July 18, 2014, 11:57pm UTC](https://forums.powershell.org/t/wildcards/2853/1 "2014-07-18T23:57:51Z")

</div>

Hi All,

So i’ve just finished the MVP Powershell course and figure i should put it too good use. Nothing better than practise, right?

We’ve moved our Exchnage services to O365 and i’ve been tasked with removing X500 / x500 (both are present) values from the “proxyAddresses” attribute for all users.

So, I’ve been able to remove an individual value from an individual AD Account using this;

```
Set-ADUser -Identity "username" -Remove @{proxyAddresses="x500Value"}
```

However, their are two values for each user. So i’d like to say;

```
Set-ADUser -Identity * -Remove @{proxyAddresses="*500*"}
```

This does run without error but doesn’t remove anything. I’m assuming that this is because it’s recognising the ‘wildcard’ (in proxyAddresses value) as a character instead of a ‘wildcard’ in the value but i’ve no idea what to do about it.

All help much appreciated.

Adam

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [July 19, 2014, 12:38am UTC](https://forums.powershell.org/t/wildcards/2853/2 "2014-07-19T00:38:54Z")

</div>

AD itself doesn’t recognize wild cards, and it’s the one processing the operation. There’s nothing you can do about it; it’s a limitation of the technology.

---

<div class="post-metadata">

**Author:** ![adam-nichols](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@adam-nichols](https://forums.powershell.org/u/adam-nichols)\
**Post date:** [July 19, 2014, 12:50am UTC](https://forums.powershell.org/t/wildcards/2853/3 "2014-07-19T00:50:28Z")

</div>

Hi Don,

Thanks for your response. Please don’t take this as anything other than my attempt to understand (i’ve a long curve ahead of me i think). 🙂

If i enter PSSession with DC and run;

```
Get-ADUser *
```
 = This outputs every user object in my environment which would indicate it had recognised the 'wildcard'? Or is something else processing this? 

Thanks,  
Adam

---

<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:** [July 19, 2014, 1:17am UTC](https://forums.powershell.org/t/wildcards/2853/4 "2014-07-19T01:17:33Z")

</div>

Certain parameters support wildcards. That \* that you passed to Get-ADUser happens to be assigned to its “Filter” parameter, which does.

However, you can’t just stick wildcards anywhere you like. The -Identity parameter to Set-ADUser and the values in the hashtable that you pass to -Remove probably don’t do any sort of wildcard matching (though I haven’t tested that myself.) That doesn’t mean that you can’t conceptually make this work, just that it takes more work on your part. You need to have a script which fetches one or more users, looks through their proxyAddresses attribute for matching values, and removes them explicitly. Something like this (again, not tested; I don’t have an AD environment up on my home lab at the moment. Remove the -WhatIf parameter from the Set-ADUser command once you’re confident it’s doing the right thing.)

```
$users = Get-ADUser * -Properties proxyAddresses
foreach ($user in $users)
{
    $addressesToRemove = @($user.proxyAddresses) -like '*500*'
    if ($addressesToRemove.Count -gt 0)
    {
        Set-ADUser -Identity $user.DistinguishedName -Remove @{proxyAddresses = $addressesToRemove} -WhatIf
    }
}
```

Note: It may be possible to speed this up by filtering the Get-ADUser command with something like -Filter ‘ProxyAddresses -like “_500_”’ , but since I can’t test that at the moment, I went something that I was confident should work.

---

<div class="post-metadata">

**Author:** ![adam-nichols](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@adam-nichols](https://forums.powershell.org/u/adam-nichols)\
**Post date:** [July 19, 2014, 1:33am UTC](https://forums.powershell.org/t/wildcards/2853/5 "2014-07-19T01:33:17Z")

</div>

Hi Dave,

Thank you for taking the time to respond to the question, scary stuff this PowerShell and there’s only so much you can pull from Google and Help files… 🙂

I shall test this (and break down the function so i understand a bit better) and will post back here to let you know how i get on. Assuming you’re interested!

Thanks Again,  
Adam

---

<div class="post-metadata">

**Author:** ![adam-nichols](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@adam-nichols](https://forums.powershell.org/u/adam-nichols)\
**Post date:** [July 21, 2014, 6:20am UTC](https://forums.powershell.org/t/wildcards/2853/6 "2014-07-21T06:20:30Z")

</div>

Hi Guys,

As promised, I got back in to the office today and tried this out.

Dave - Thanks very much, did the trick. The only change i had to make, ironically, is that i had to specify “\*” as a ‘-Filter’!

So workable script turned out as;

```
$users = Get-ADUser -Filter * -Properties proxyAddresses
foreach ($user in $users)
{
    $addressesToRemove = @($user.proxyAddresses) -like '*500*'
    if ($addressesToRemove.Count -gt 0)
    {
        Set-ADUser -Identity $user.DistinguishedName -Remove @{proxyAddresses = $addressesToRemove}
    }
}
```

Thanks for all your help! Much appreciated.

Adam

---

<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:47pm UTC](https://forums.powershell.org/t/wildcards/2853/7 "2024-05-16T20:47:45Z")

</div>

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


