Solved

vbscript, email results

Posted on 2016-08-08
2
23 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
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Input past end of file vbs script 9 68
Remove Office macro by VC++ 10 71
Vbscript 8 66
VB Script to add site to Java Exception List 4 13
Unlike scripting languages such as C# where a semi-colon is used to indicate the end of a command, Microsoft's VBScript language relies on line breaks to determine when a command begins and ends. As you can imagine, this quickly results in messy cod…
Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 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

18 Experts available now in Live!

Get 1:1 Help Now