anuroopkoka2005
asked on
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
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
https://www.experts-exchange.com/questions/24301124/script-that-can-apply-the-mailbox-quota-to-the-user-ids-listed-in-the-excel-file.html
Kindly help me....
https://www.experts-exchange.com/questions/24301124/script-that-can-apply-the-mailbox-quota-to-the-user-ids-listed-in-the-excel-file.html
Kindly help me....
ASKER
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
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
ASKER
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.Fi leSystemOb ject")
DataFileName = obArgs.Item(0)
Set DataFile = FileSysObj.OpenTextFile(Da taFileName , 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(vDistinguishedNa me, 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(strsAMAccount Name)
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.Connec tion")
Set Com = createobject("ADODB.Comman d")
' 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,distinguis hedName;su btree"
Com.ActiveConnection = Conn
Com.CommandText = strQuery
Set Rs = Com.Execute
GetDNFromSam = Rs.Fields("distinguishedNa me")
'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,vOverQuotaLimi t,vHardLim it)
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_WRIT E
Set objMailbox = objPerson.GetInterface("IM ailboxStor e")
'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.EnableStoreDefa ults = false
objPerson.DataSource.Save
End If
Set objMailbox = Nothing
Set objPerson = Nothing
End Sub
'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.Fi
DataFileName = obArgs.Item(0)
Set DataFile = FileSysObj.OpenTextFile(Da
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(vDistinguishedNa
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(strsAMAccount
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.Connec
Set Com = createobject("ADODB.Comman
' 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,distinguis
Com.ActiveConnection = Conn
Com.CommandText = strQuery
Set Rs = Com.Execute
GetDNFromSam = Rs.Fields("distinguishedNa
'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,vOverQuotaLimi
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_WRIT
Set objMailbox = objPerson.GetInterface("IM
'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.EnableStoreDefa
objPerson.DataSource.Save
End If
Set objMailbox = Nothing
Set objPerson = Nothing
End Sub
I think we can simplify that considerably... won't be long.
Chris
ASKER
thank uuu
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the script..
I will check this script and let u know....
I will check this script and let u know....
ASKER
Great script thanks :-)
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