On Sep 13, 8:12 pm, Shawn Dumas <ShawnDu...@xxxxxx>
wrote:
> param ([array]$users=$(throw "Need Users..."))
> foreach ($user in $users)
> {
> $u = (ldap
> "(&(objectCategory=person)(objectClass=user)(samaccountname=$user))").GetDi*rectoryEntry()
> if ($u.proxyAddresses)
> {
> $pa = $u.proxyAddresses | ?{$_ -match 'bad-address'}
> $pa = '@("' + ([string]::join('","', $pa)) + '")'
> $u.PutEx(2, 'proxyAddresses', (invoke-expression "$pa"))
> $u.SetInfo()
> }
>
> }
>
> This works but why on earth do I have to get so jiggy with the array before
> PutEx will take it? I remember going through similar hoops trying to get arrays as
parameters passed correctly; a bit painful. I still muck it up now and
again. Powershell has a habit of unrolling arrays before passing them
anywhere, so try using the array constructor:
$pa = $u.proxyAddresses | ?{$_ -match 'bad-address'}
$u.PutEx(2, 'proxyAddresses', (,$pa))
I'm not able to test this, so it might not work outright, but
Hopefully it'll give you some ideas. So, why do this? By putting the
array constructor in front of it, I'm making an array with 1 element,
which is your $pa array. Powershell will unroll it, leaving the inner
array intact (hopefully!)
Hope this helps
- Oisin