TechRepublic
recently asked members to submit their favorite Network Administration scripts
for possible publication. One of the first to make a submission was Lee Mason. For his effort, Lee earned $300
and the satisfaction of seeing his scripts published on TechRepublic.


Earn $100 for your admin script

Let us pay
you for your original scripts so that we can publish them as downloads on
TechRepublic and allow your fellow IT professionals to benefit from your
scripting savvy. We only ask that you put in the appropriate comments to your
scripts so that it’s easy to tell what the script is doing and which variables
might need to be customized. Send us your original Windows
admin scripts
and we’ll pay you $100
for each one that we publish as a TechRepublic download.


In their own words

Editor’s note: Besides the Listings you see below, I have also placed the listings in
sidebars. The sidebars should be more useful for cutting and pasting the
scripts. If they aren’t, make a note in the discussion thread and I’ll come up
with a different solution.

Listing A

This script
adds a specified domain group to another specified local group on a given
machine.

(Listing A):

‘Script written by L Mason v1.0
‘This script adds a specified domain group
‘To another specified local groupon a given machine.

Dim DomainName
Dim UserAccount

Set net = WScript.CreateObject(“WScript.Network”)
local = net.ComputerName
DomainName = “mydomainname” ‘enter your domain name here
UserAccount = “mydomaingroup” ‘enter the domain group
set group = GetObject(“WinNT://”&local&”/mylocalgroup”) ‘enter the local group

‘adds the group.
group.Add “WinNT://”& DomainName &”/”& UserAccount &””

Listing B

This script
checks the inbox for read mail and (in this case) moves it to an folder. It also counts unread mail in mailbox.

(Listing B):

Private Sub Application_NewMail()

‘Written by Lee Mason
‘Platform: Outlook VBA
‘Purpose: Checks inbox for read mail and (in this case) moves it to
‘an folder. Also counts unread mail in mailbox.

——————

On Error goto 1000

‘Declares and initialised variables
Dim myOlApp As Application
Dim myNameSpace As NameSpace
Dim myibox As MAPIFolder
Dim mydelitems As MAPIFolder
Dim myitem As MailItem
Dim n As Integer
Dim unreadmail As Integer

n = 1
unreadmail = 0
Set myOlApp = CreateObject(“Outlook.Application”)
Set myNameSpace = myOlApp.GetNamespace(“MAPI”)
Set myibox = myNameSpace.GetDefaultFolder(olFolderInbox)
Set mymovefolder = myibox.Folders(“Old Items”)

‘Looks at items in the inbox and moves to
‘Inbox/Old Items Folder if read, otherwise adds to the
‘running count of unread items.

For n = 1 To myibox.Items.Count
    Set myitem = myibox.Items(n)
    If myitem.UnRead = True Then
        unreadmail = unreadmail + 1
    Else: myitem.Movemymovefolder
   
    End If
Next n

1000 msgboxerr.name

Listing C

This script
uses FSO to calculate the age of file by finding the difference between its
creation date and now. Useful for clearing out unused files
by adding a simple delete operation to the IF
statement. I’ve included amsgbox operation for place holding
here.

(Listing C):

‘Check file age
‘Written by Lee Mason
‘This script uses FSO to calculate the age of file by finding the difference
‘between its creation date and now.
‘Useful for clearing out unused files by adding a simple delete operation to the if statement.
‘I’ve included amsgbox operation for placeholding here.

‘declare variables for fso
Dim fol
Dim fil
Dim fso
dim difftype
dim maxage

Set fso = CreateObject(“Scripting.FileSystemObject”)

‘set the TYPE of difference you want here, ie “D”=days, “M”=months “Y”=years
difftype=”D”
‘set the maximum age of the file here
maxage =2

‘Add your own path here
Set fol = fso.GetFolder(“C:\windows”)

For Each fil In fol.files
If DateDiff(difftype,fil.DateCreated,Now())>=maxage Then MsgBoxfil.name & ” ” & fil.DateCreated
Next

‘reclaim memory
Set tf = Nothing
Set fol = Nothing