Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

VBscript to Hide from exchange list

Posted on 2011-02-15
14
1,482 Views
Last Modified: 2012-05-11
I have a vbscript that works perfectly well at disabling an account and removing all group membership apart from the Primary Group.

The subroutine is shown below.  If however I uncomment the two lines for hiding from the exchange list it comes up with an error code  -2147463153

would you be able to tell me what is wrong

'--------------------------------------------------------------------------------------------------
' This subroutine Disables users.
'--------------------------------------------------------------------------------------------------

Sub DisableUser
      
'*********************************************************************************
'  Disable the User Account
'*********************************************************************************

      objUser.AccountDisabled = True
      objUser.SetInfo

      On Error Resume next

      objUser.Put "msExchHideFromAddressLists", True
      objUser.SetInfo

      If Err.Number = 0 Then
            Report "User hidden successfully."
      Else
            Report Err.number
            Report Err.Desciption
            Report "Sorry something went wrong, check user name."
      End If

' Enumerate all direct group memberships (except the "primary" group).
For Each objGroup In objUser.Groups
' Remove the user from the group.
objGroup.Remove(objUser.AdsPath)
Next


End Sub
0
Comment
Question by:WNottsC
  • 7
  • 6
14 Comments
 

Author Comment

by:WNottsC
ID: 34904343
I have just changed:-

objUser.Put "msExchHideFromAddressLists", True

to

objUser.msExchHideFromAddressLists = True

and get the following error

438    Object doesn't support this property or method
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 34904505
Hi

The code mentioned by you for hiding works and no changes required.
objUser.Put "msExchHideFromAddressLists", True
objuser.setinfo

can you give err.clear at beginning of subroutine and try
0
 

Author Comment

by:WNottsC
ID: 34904548
I still get the -2147463153  error
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 12

Expert Comment

by:prashanthd
ID: 34904809
Can you give the description of the error, can you also check if the hide value is being set to true.
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 34905609
Hi

Does the user whom you are trying to hide have exchange attributes, is the user mail enabled?
We cannot hide user if he is not mail enabled.

I had tested the script against mail enabled user and it worked fine, for non mail enabled user it threw -2147463153  error.

0
 
LVL 11

Expert Comment

by:Tasmant
ID: 34905924
you could try this:
const ADS_PROPERTY_UPDATE = 2
objUser.PutEx ADS_PROPERTY_UPDATE, "msExchHideFromAddressLists", True
objUser.SetInfo

or maybe this
objUser.Get("msExchHideFromAddressLists")
objUser.Put "msExchHideFromAddressLists", True
0
 

Author Comment

by:WNottsC
ID: 34906376
this error does not bring back a description, it does have exchange attributes but with exchange 2007 you no longer have tabs on the AD user account for the exchange information.  Not sure if exchange 2007 is the reason this error is coming up.

Tried it again on a different account and it is still having the same issue. even using

objUser.Get("msExchHideFromAddressLists")
objUser.Put "msExchHideFromAddressLists", True
objUser.SetInfo



0
 

Author Comment

by:WNottsC
ID: 34906540
we are using this code for connecting to the object could this be the issue.  However it works for disabling the account and removing group membership just not the exchange list

Set objUser = GetObject("WinNT:// { NETBIOS Domain name } " & "/" & strstaffID)
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 34906542
Can you try to fetch the information and display the present value, using the objUser.Get("msExchHideFromAddressLists") to check the error it is throwing. Try to only get the value, not set the value.
0
 

Author Comment

by:WNottsC
ID: 34906555
this gives us a 2147463155 error
0
 

Author Comment

by:WNottsC
ID: 34906562
sorry and the description for that error is The directory property cannot be found in the cache
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 34906656
can you use adsiedit to check if the property exists for the user.
0
 

Author Comment

by:WNottsC
ID: 34906665
the property exists but it is <not set>
0
 
LVL 12

Accepted Solution

by:
prashanthd earned 500 total points
ID: 34913964
LDAP has to be used to set this info. WinNT cannot be used to refrence this.

http://www.rlmueller.net/UserAttributes.htm 
check Spreadsheet of attributes exposed by the WinNT provider

Try the below code, set value of staffid to struser
'On Error Resume Next

struser = "staffid"

Dim objRootDSE, strDomain, strUsername, objConnection, objCommand, objRecordSet, strDN
Const ADS_SCOPE_SUBTREE = 2

' Get domain components
Set objRootDSE = GetObject("LDAP://RootDSE")
strDomain = objRootDSE.Get("DefaultNamingContext")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(inputfile, 1)

' Set ADO connection
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

' Set ADO command
Set objCommand = CreateObject("ADODB.Command")
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = "SELECT distinguishedName FROM 'LDAP://" & strDomain & "' WHERE objectCategory='person' AND samaccountname = '" & struser & "'"

' Set recordset to hold the query result
Set objRecordSet = objCommand.Execute

' If a Group was found - Retrieve the distinguishedName
If Not objRecordSet.EOF Then
    strDN = "LDAP://" & objRecordSet.Fields("distinguishedName").Value
    
    Set objUser = GetObject(strDN)
    Err.Clear
    
    objUser.Put "msExchHideFromAddressLists", True
    objUser.SetInfo
    
    If Err.Number = 0 Then
        Report "User hidden successfully."
    Else
        Report Err.number
        Report Err.Desciption
        Report "Sorry something went wrong, check user name."
    End If
    
Else
    
    WScript.Echo "user not found"
    
End If

Open in new window

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question