10
Aug/090
Aug/090
Get the Directory Size via script
The Script uses the FileSystemObject to retrieve the size of a Directory.
Takes 1 Argument (The Directory Path)
File: GetDirectorySize.js
1 2 3 4 5 6 7 8 | function main() { var fs = WScript.CreateObject("Scripting.FileSystemObject"); var dir = fs.GetFolder(WScript.Arguments(0)); WScript.Echo (dir.Size); } main(); |
311 views
26
Jul/090
Jul/090
Unlock, Enable and Reset Password on a User Account in Active Directory via Script
JSscript that unlocks a User account in AD using the WinNT Provider.
Save as “UnlockAccount.js” or whatever you prefer and run “cscript UnlockAccount.js [Domain] [UserName] [Optional:Password]“
Takes 2 Arguments (Domain Name, UserName,Optional:NewPassword)
?Download MT_UnlockAccount.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | UnlockAccount( WScript.Arguments(0), WScript.Arguments(1)); function UnlockAccount( domain, account) { try { var user = GetObject("WinNT://" + domain + "/" + account); if( user.AccountDisabled) { user.AccountDisabled = false; user.SetInfo(); WScript.Echo("Account Enabled"); } else { WScript.Echo("Account was Enabled" ); } if( user.IsAccountLocked ) { user.IsAccountLocked = false; user.SetInfo(); WScript.Echo("Account Unlocked"); } else { WScript.Echo("Account was not locked" ); } if (WScript.Arguments.Count() == 3) { user.SetPassword(WScript.Arguments(2)); WScript.Echo("Password Updated"); } else { WScript.Echo("Password not changed"); } } catch( e ) { WScript.Echo( "Error: " + e.description ); } } |
1,154 views
23
Jul/090
Jul/090
Delete files by date modified
Another small Java script that deletes files or directories older than a specified date.
Please uncomment the // subdir.Delete(true); and // file.Delete(true); sections in order to perform the delete actions.
Takes 1 Arguments (DirectoryPath)
Usage: cscript SRV_Cleanup.js [DirectoryPath]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | function clean(dir, cutoff, exclude) { loop: for (var enu = new Enumerator(dir.SubFolders); !enu.atEnd(); enu.moveNext()) { var subdir = enu.item(); for (var i in exclude) if (exclude[i].test(subdir.Path)) continue loop; clean(subdir, cutoff, exclude); if ((new Date(subdir.DateLastModified)).valueOf(); cutoff) { WScript.Echo("rmdir " + subdir.Path); // subdir.Delete(true); } } for (var enu = new Enumerator(dir.Files); !enu.atEnd(); enu.moveNext()) { var file = enu.item(); if ((new Date(file.DateLastModified)).valueOf(); cutoff) { WScript.Echo("del " + file.Path); // file.Delete(true); } } } function main() { if (WScript.Arguments.Length == 0) WScript.Quit(); var exclude = new Array(WScript.Arguments.Length - 1); for (var i = 0; i < exclude.length; i++) exclude[i] = new RegExp(WScript.Arguments.Item(i + 1) + "$", "i"); var fs = WScript.CreateObject("Scripting.FileSystemObject"); var age = 1000 * 60 * 60 * 24 * 10; var cutoff = (new Date()).valueOf() - age; clean(fs.GetFolder(WScript.Arguments.Item(0)), cutoff, exclude); } main(); |
193 views

(3 votes, average: 4.33 out of 5)