Query or Script needed

Icontech
Icontech used Ask the Experts™
on
Hi Experts,
Query or Script needed to remove SMTP address and SIP Address (OCS) from a user account.
Please let me know if you require more details on this...
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Chris DentPowerShell Developer
Top Expert 2010

Commented:

PowerShell? :)

Naturally you should use this on a test account first to make sure it behaves as expected.

Chris
# Define the account
$User = [ADSI]"LDAP://CN=User,OU=somewhere,DC=domain,DC=com"

$User.Get("proxyAddresses") | Where-Object { $_ -Like "SIP:*" } | ForEach-Object {
  # Call PutEx with 4 (ADS_PROPERTY_REMOVE) to remove a single value from proxyAddresses (a multi-value property)
  $User.PutEx(4, "proxyAddresses", @("$_"))
  # Commit the change
  $User.SetInfo()
}

Open in new window

Author

Commented:
Chris-Dent, Please could you get me a VB Script for this?
Thank You,
Chris DentPowerShell Developer
Top Expert 2010

Commented:

Sure, it's pretty similar.

Chris
Const ADS_PROPERTY_REMOVE = 4

Set objUser = GetObject("LDAP://CN=User,OU=somewhere,DC=domain,DC=com")

arrProxyAddresses = objUser.Get("proxyAddresses")
For Each strProxyAddress in arrProxyAddresses
  If InStr(1, strProxyAddress, "SIP:", VbTextCompare) > 0 Then
    objUser.PutEx ADS_PROPERTY_REMOVE, "proxyAddresses", strProxyAddress
    objUser.SetInfo
  End If
Next

Open in new window

Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Chris HudsonCloud Security Architect

Commented:
1)open a notepad and copy the follwing with necessary changes .REMEMBER TO COPY THE LAST "-"
   and save it as <filname.ldf>

        dn: <DistinguishedName of User Object>
        changetype: Modify
        delete: <attributeName>
        -

2)execute ldifde -i -f <path of ldf file ,which u created in step1>

DONE


Author

Commented:
Chris,
i receive the error mentioned below for your VB Script:

Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Documents and Settings\TEST\Desktop\smtp.vbs(8, 5) Active Directory: Unspecified error
 I modified the LDAP path and saved the the file as smtp.vbs
please check for the same and update me as soon as possible.
Thank You...

Author

Commented:
Hello Experts,
Is there any possibility to get this query in C# script?
Thank you,
PowerShell Developer
Top Expert 2010
Commented:

Sorry, I keep forgetting to come back to this one.

C# is compiled not a scripting language. But I guess you know that and just want C#?

It should go something like this.

Chris
// Define the account
DirectoryEntry adUser = new DirectoryEntry("LDAP://CN=User,OU=somewhere,DC=domain,DC=com")

// Loop through the addresses - may be missing a cast
foreach (String address in adUser.InvokeGet) {
  // Test the address
  if (address.StartsWith("SIP:", StringComparison.InvariantCultureIgnoreCase)) {
    // Remove the address
    adUser.Invoke("PutEx", new Object[] { 4, "proxyAddresses", new String[] { address } })
    adUser.CommitChanges()
  }
}

Open in new window

Author

Commented:
Hi Chris,
Thanks for coming back for me....
I will check for this and let you know...
Thanks Again......
:-)

Author

Commented:
hi,

we received error on this... and we have dropped this..

But anyway i give points to mike for his effort..

thanks mike

Author

Commented:
Received error... thanks for your effort

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial