Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

does this script take the user logon name as input from the csv file and ask us how much storage limit u want to set

Posted on 2009-04-07
8
Medium Priority
?
214 Views
Last Modified: 2012-05-06
does this script take the user logon name as input from the csv file and ask us how much storage limit u want to set

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24301124.html

Kindly help me....
0
Comment
Question by:anuroopkoka2005
[X]
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
  • 5
  • 3
8 Comments
 
LVL 71

Expert Comment

by:Chris Dent
ID: 24085833

Is that what you need something to do? Read a CSV, get the account corresponding to the username and set the storage limits?

Can I see a sample of your input file?

And which quota limit(s) are you wanting to set? Soft, Hard and Warning?

Chris
0
 
LVL 4

Author Comment

by:anuroopkoka2005
ID: 24086029
Hi Chris,

script should read the txt file that has username of the users and ask me how much u want to set.

I want to set all the 3 quota limits...

Thanks

0
 
LVL 4

Author Comment

by:anuroopkoka2005
ID: 24086255
i found a script on the internet...but is throwing error..

'This script sets the StoreQuota, OverQuotaLimit, Hardlimit for a mailbox.

' USAGE: cscript SetMailboxQuota.vbs DATAFILE
' This code has to be run on a box that has ESM or Exchange 2003 Installed.

Dim obArgs
Dim cArgs

Set obArgs = WScript.Arguments
cArgs = obArgs.Count


Main

Sub Main()
Dim FileSysObj
Dim DataFileName
Dim DataFile
Dim sAMAccoutname
Dim vDistinguishedName

Const ForReading = 1, ForWriting = 2, ForAppending = 8, TristateFalse = 0

On error Resume Next
If cArgs <> 1 Then
      WScript.Echo "Usage: cscript SetMailboxQuota.vbs DATAFILE"
      Exit Sub
End If

Set FileSysObj = CreateObject("Scripting.FileSystemObject")

DataFileName = obArgs.Item(0)

Set DataFile = FileSysObj.OpenTextFile(DataFileName, ForReading, False,0)

Do While Not DataFile.AtEndOfStream
    sAMAccoutname = DataFile.ReadLine

    vDistinguishedName = GetDNFromSam(sAMAccoutname)

    If vDistinguishedName <> "" then
        WScript.Echo "Sam Account Name:" & sAMAccoutname
        WScript.Echo "Distinguished Name:" & vDistinguishedName

        'Please change limits as per your needs
        'The Size Specified is in Kb
        Call SetLimits(vDistinguishedName, 18432,20480,25600)

        If Err.Number <> 0 Then
              sMsg = "Error Setting Limits"
           sMsg = sMsg & Err.Number & " " & Err.Description
           WScript.Echo sMsg
    End If
    else
       WScript.Echo "Could not get Distinguished Name for " & sAMAccoutname
    end if

    WScript.Echo
Loop
   
DataFile.Close
Set DataFile = Nothing
Set FileSysObj = Nothing

End Sub

Function GetDNFromSam(strsAMAccountName)

Dim iAdCont
Dim iAdGC
Dim Conn
Dim Com
Dim Rs
Dim varGCAdsPath
Dim strQuery

   ' Get the Global Catalog
   Set iAdCont = GetObject("GC:")
 
   For Each iAdGC In iAdCont
      varGCAdsPath = iAdGC.ADsPath
   Next

   Set Conn = createobject("ADODB.Connection")
   Set Com = createobject("ADODB.Command")

   ' Open the Connection
   Conn.Provider = "ADsDSOObject"
   Conn.Open "ADs Provider"

   ' Build the query to find the user based on his Alias
   strQuery = "<" & varGCAdsPath & ">;(sAMAccountName=" & strsAMAccountName & ");mailNickName,distinguishedName;subtree"

   Com.ActiveConnection = Conn
   Com.CommandText = strQuery
   Set Rs = Com.Execute

   GetDNFromSam = Rs.Fields("distinguishedName")

   'Clean Up
   Rs.Close
   Conn.Close

   Set Rs = Nothing
   Set Com = Nothing
   Set Conn = Nothing
   Set iAdCont = Nothing
   Set iAdGC = Nothing

End Function


Sub SetLimits(strUserDN, vStoreQuota,vOverQuotaLimit,vHardLimit)

Const AD_MODE_READ_WRITE = 3
Dim strLDAP
Dim objPerson
Dim objMailbox

    strLDAP = "LDAP://" & strUserDN

    Set objPerson = CreateObject("CDO.Person")
 
    objPerson.DataSource.Open strLDAP,,AD_MODE_READ_WRITE

    Set objMailbox = objPerson.GetInterface("IMailboxStore")

    'check if the user is mailbox enabled
    If objMailbox.HomeMDB = "" Then
        Wscript.Echo "No Mailbox found."
    Else
       'Give Warning at
        Wscript.Echo "Current StoreQuota:" & objMailbox.StoreQuota
        Wscript.Echo "Setting StoreQuota to:" & vStoreQuota & "(KB)"
        objMailbox.StoreQuota = vStoreQuota

       'Prevent Sending at
       Wscript.Echo "Current OverQuotaLimit:" & objMailbox.OverQuotaLimit & "(KB)"
       Wscript.Echo "Setting OverQuotaLimit to:" & vOverQuotaLimit & "(KB)"
       objMailbox.OverQuotaLimit = vOverQuotaLimit

       'Prevent Sending and Recieving at
       Wscript.Echo "Current Hardlimit:" & objMailbox.HardLimit & "(KB)"
       Wscript.Echo "Setting StoreQuota to:" & vHardLimit & "(KB)"
       objMailbox.HardLimit = vHardLimit

       ' Clearing defaults
       Wscript.Echo "Disabling Database Defaults"
       objMailbox.EnableStoreDefaults = false
       objPerson.DataSource.Save

    End If

    Set objMailbox = Nothing
    Set objPerson = Nothing

End Sub
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 71

Expert Comment

by:Chris Dent
ID: 24086266

I think we can simplify that considerably... won't be long.

Chris
0
 
LVL 4

Author Comment

by:anuroopkoka2005
ID: 24086298
thank uuu
0
 
LVL 71

Accepted Solution

by:
Chris Dent earned 2000 total points
ID: 24086452

This kind of thing should do it.

It will pop up 3 boxes asking for each limit in Mb (must be numeric, it should error and die if you try and enter anything other than that).

Then it opens up a text file, currently set at the top as INPUT_FILE. We can have it ask for a name / path if you prefer. The file is expected to be:

username1
username2
username3
etc

Then for each of the users it sets any limit you've set to be greater than 0. If you've set 0 it doesn't do anything with the value. We can change it to unset a limit if you like though.

Chris

Const INPUT_FILE = "filename.txt"
 
Function GetObjectDN(strObject, strDomain)
  ' Return Type: String
  '
  ' Returns a Distinguished Name for an Object from it's NT SAM ID.
  ' This will only function for valid object types within an NT Domain structure.
 
  Const ADS_NAME_INITTYPE_GC = 3
  Const ADS_NAME_TYPE_1779 = 1
  Const ADS_NAME_TYPE_NT4 = 3
 
  If strDomain = "" Then
    Dim objNetwork : Set objNetwork = CreateObject("WScript.Network")
    strDomain = objNetwork.UserDomain
    Set objNetwork = Nothing
  End If
 
  On Error Resume Next : Err.Clear
  Dim objNameTranslate : Set objNameTranslate = CreateObject("NameTranslate")
 
  objNameTranslate.Init ADS_NAME_INITTYPE_GC, ""
  objNameTranslate.Set ADS_NAME_TYPE_NT4, strDomain & "\" & strObject
  Dim strObjectDN : strObjectDN = objNameTranslate.Get(ADS_NAME_TYPE_1779)
 
  If Err.Number <> 0 Then strObjectDN = ""
 
  Set objNameTranslate = Nothing
  On Error Goto 0
 
  GetObjectDN = strObjectDN
End Function
 
'
' Main Code
'
 
' Request the values for each limit
 
Dim intWarnLimit : intWarnLimit = CInt(InputBox("Please enter the warning limit in Mb", "Warning Limit", 0))
Dim intSoftLimit : intSoftLimit = CInt(InputBox("Please enter the soft limit in Mb (Prohibit Send)", "Soft Limit", 0))
Dim intHardLimit : intHardLimit = CInt(InputBox("Please enter the hard limit in Mb (Prohibit Send and Receive)", "Hard Limit", 0))
 
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFile : Set objFile = objFSO.OpenTextFile(INPUT_FILE, 1, False, 0)
 
Do While Not objFile.AtEndOfStream
 
  Dim strUsername : strUsername = objFile.ReadLine
 
  Dim strDN : strDN = GetObjectDN(strUsername, "")
 
  If strDN <> "" Then
 
    Dim objUser : Set objUser = GetObject("LDAP://" & strDN)
 
    If intWarnLimit > 0 Or intSoftLimit > 0 Or intHardLimit > 0 Then
      objUser.Put "mDBUseDefaults", False
      objUser.SetInfo
    End If
 
    If intWarnLimit > 0 Then
      ' Put the value, convert to Kb
      objUser.Put "mDBStorageQuota", intWarnLimit * 1024
      objUser.SetInfo
    End If
 
    If intSoftLimit > 0 Then
      ' Put the value, convert to Kb
      objUser.Put "mDBOverQuotaLimit", intSoftLimit * 1024
      objUser.SetInfo
    End If
 
    If intHardLimit > 0 Then
      ' Put the value, convert to Kb
      objUser.Put "mDBOverHardQuotaLimit", intHardLimit * 1024
      objUser.SetInfo
    End If
 
    Set objUser = Nothing
  End If
Loop

Open in new window

0
 
LVL 4

Author Comment

by:anuroopkoka2005
ID: 24086510
Thanks for the script..

I will check this script and let u know....
0
 
LVL 4

Author Closing Comment

by:anuroopkoka2005
ID: 31567408
Great script thanks :-)
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

How to deal with a specific error when using the Enable-RemoteMailbox cmdlet to create a mailbox in the cloud-based service, for an existing user in an on-premises Active Directory.
Are you an Exchange administrator employed with an organization? And, have you encountered a corrupt Exchange database due to which you are not able to open its EDB file. This article will explain all the steps to repair corrupt Exchange database.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…
Suggested Courses

636 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