Solved

vbscript, email results

Posted on 2016-08-08
2
35 Views
Last Modified: 2016-08-08
I have a script that saige helped me put together for file shares.  The script excludes all default file shares.

I want to have this email the results via smtp, the name of the computer, service name and path location.  Script below.  Thanks in advance.

Dim strComputer, strResult
Dim exclusions

If Trim(strComputer) = "" Then strComputer = "."
exclusions = Array("Apps$", "sys$")

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colShares = objWMIService.ExecQuery("SELECT * FROM Win32_Share WHERE NOT Type=2147483648 AND NOT Type=2147483649 AND NOT Type=2147483650 AND NOT Type=2147483651")
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Add

For each objShare in colShares
      If UBound(Filter(exclusions, objShare.Name, True, 1)) < 0 Then
            strResult = strResult + "AllowMaximum: " & vbTab & objShare.AllowMaximum & vbcrlf &_
                  "Caption: " & vbTab & objShare.Caption & vbcrlf &_
                  "MaximumAllowed: " & vbTab & objShare.MaximumAllowed  & vbcrlf &_
                  "Name: " & vbTab & objShare.Name & vbcrlf &_
                  "Path: " & vbTab & objShare.Path & vbcrlf &_
                  "Type: " & vbTab & objShare.Type & vbcrlf & vbcrlf
      End If
Next
wscript.echo "Shares on computer: " & strComputer & vbcrlf & vbcrlf & strResult
'wscript.echo "Done"
0
Comment
Question by:Rob Shorts
[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
2 Comments
 
LVL 35

Accepted Solution

by:
Kimputer earned 500 total points
ID: 41747213
Dim strComputer, strResult
Dim exclusions

If Trim(strComputer) = "" Then strComputer = "."
exclusions = Array("Apps$", "sys$")

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colShares = objWMIService.ExecQuery("SELECT * FROM Win32_Share WHERE NOT Type=2147483648 AND NOT Type=2147483649 AND NOT Type=2147483650 AND NOT Type=2147483651")
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Add

For each objShare in colShares
      If UBound(Filter(exclusions, objShare.Name, True, 1)) < 0 Then
            strResult = strResult + "AllowMaximum: " & vbTab & objShare.AllowMaximum & vbcrlf &_
                  "Caption: " & vbTab & objShare.Caption & vbcrlf &_
                  "MaximumAllowed: " & vbTab & objShare.MaximumAllowed  & vbcrlf &_
                  "Name: " & vbTab & objShare.Name & vbcrlf &_
                  "Path: " & vbTab & objShare.Path & vbcrlf &_
                  "Type: " & vbTab & objShare.Type & vbcrlf & vbcrlf
      End If
Next
wscript.echo "Shares on computer: " & strComputer & vbcrlf & vbcrlf & strResult
'wscript.echo "Done"

Dim objMessage, Rcpt 

Set objMessage = CreateObject("CDO.Message") 
Rcpt = Chr(34) & "TO name" & Chr(34) & "<email@address.com>"  'change
objMessage.Subject = "insert subject"  'change
objMessage.From = """from name"" <email@address.com>"  'change
objMessage.To = Rcpt 
objMessage.HTMLBody = "Shares on computer: " & strComputer & vbcrlf & vbcrlf & strResult

objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.server.com" 'change

'Server port (typically 25)
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 

objMessage.Configuration.Fields.Update

objMessage.Send 

Open in new window


Obviously, everywhere you see the 'change comment, change what's needed.
0
 

Author Closing Comment

by:Rob Shorts
ID: 41747230
Thank you!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 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