Solved

script to netsend or email disk name daily

Posted on 2006-11-15
6
445 Views
Last Modified: 2012-06-22
Hi,

I need a script that can be set to run daily with task manager that will net send (1st preference) or email (least preferable) the volume name of an attached USB drive.

WHY= I have 12 servers that use USB drive for backups. Usually G: drive.
The drives are named Monday, Tuesday, Wednesday etc. etc.

At 4.00PM I want all the servers to notify our backup admin which drive is attached so that if one site forgot to change the drive over, he can contact them in advance to the backup job failing later in the evening.

THanks a lot.
0
Comment
Question by:viperacom
  • 3
  • 2
6 Comments
 
LVL 23

Expert Comment

by:Christopher Kile
ID: 17947816
Write a VBScript that does the job, then schedule it using Scheduled Tasks.

The FileSystemObject provides objects and methods for you to use to get the volume name.
0
 
LVL 7

Expert Comment

by:yotamsher
ID: 17950733
here is a script similar to what you need:
it sneds through netsend (to * which you have to change) the labels of all removable drives on the computer.
if you need assistance with running it through scheduled tasks, please post here
be sure to run it, with cscript

'-----------------------------------------
'              drives.vbs
'-----------------------------------------

dim filesys, filetxt, getname, path, compname
Set filesys = CreateObject("Scripting.FileSystemObject")
Set Drives = filesys.Drives
Set WshNetwork = WScript.CreateObject("WScript.Network")
compname = WshNetwork.ComputerName
for each DiskDrive in Drives
      if DiskDrive.IsReady then
            DriveLetter = DiskDrive.DriveLetter
            DT = DiskDrive.DriveType
            Volume = DiskDrive.VolumeName
            Select Case DT
                  Case "0" DriveType = "Unknown type of drive"
                  Case "1" DriveType = "Removable drive"
                  Case "2" DriveType = "Fixed drive"
                  Case "3" DriveType = "Network drive"
                  Case "4" DriveType = "CD-ROM drive"
                  Case "5" DriveType = "RAM Disk"
            End Select


            WScript.echo DriveLetter  & ": type=" & DriveType
            if DT = 1 then
                  Dim shell
                  dim command
                  command ="net send * " & Chr(34) &"[" & compname & "] "& DriveLetter  & ": (" & Volume & ") type=" & DriveType & Chr(34)  
                  WScript.echo command
                  Set shell = CreateObject("WScript.Shell")
                  shell.Run command , 1, false
                  Set shell = Nothing
            end if
      end if

next
set WshNetwork = nothing
Set Drives = nothing
set filesys = nothing      
0
 
LVL 1

Author Comment

by:viperacom
ID: 17951823
awesome that works really well.

PS: Can I make it net send "no removable drive" if one is not found?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:viperacom
ID: 17953093
ahh... problem... the USB hard drives show up as fixed disk.
Tell you what, I know that they are usually G: Drive so can you please show how to make it just send the volumename of G: Drive?

thank you.
0
 
LVL 1

Author Comment

by:viperacom
ID: 17953099
oh sorry, and can it send the amount of free space and filenames contained (there are only ever around 10 files in total).
I am happy to award more pionts
0
 
LVL 7

Accepted Solution

by:
yotamsher earned 500 total points
ID: 17959393
Hey

here is what you asked for
the files part, is looking for files in g:\, not in sub directories

'-----------------------------------------
'              drives-2.vbs
'-----------------------------------------

dim filesys, filetxt, getname, path, compname
Set filesys = CreateObject("Scripting.FileSystemObject")
Set Drives = filesys.Drives
Set WshNetwork = WScript.CreateObject("WScript.Network")
compname = WshNetwork.ComputerName
Set DiskDrive = filesys.Drives("G")
if DiskDrive.IsReady then
      DriveLetter = DiskDrive.DriveLetter
      DT = DiskDrive.DriveType
      Select Case DT
            Case "0" DriveType = "Unknown type of drive"
            Case "1" DriveType = "Removable drive"
            Case "2" DriveType = "Fixed drive"
            Case "3" DriveType = "Network drive"
            Case "4" DriveType = "CD-ROM drive"
            Case "5" DriveType = "RAM Disk"
       End Select


      WScript.echo DriveLetter  & ": type=" & DriveType
      Volume = DiskDrive.VolumeName
      FreeSpace=DiskDrive.AvailableSpace
      dim files
      files = "files: "
      Set objFolder = filesys.GetFolder("g:\")
      Set colFiles = objFolder.Files
      For Each objFile in colFiles
            files = files & objFile.Name & " ,"
      Next

      Dim shell
      dim command
      command ="net send * " & Chr(34) &"[" & compname & "] "& DriveLetter  & ": (" & Volume & ") type=" & DriveType & " ["& FreeSpace & "] free " & files & Chr(34)
      WScript.echo command
      Set shell = CreateObject("WScript.Shell")
      shell.Run command , 1, false
      Set shell = Nothing
end if

set WshNetwork = nothing
Set Drives = nothing
set filesys = nothing    
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
File.WriteAllLines problem at random C# ASP.NET 6 65
strDist challenge 35 97
groupSum6 challenge 6 76
Please explain: Aspect Oriented Programming 2 84
A short article about a problem I had getting the GPS LocationListener working.
This is an explanation of a simple data model to help parse a JSON feed
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now