Ron Shorts
asked on
vbscript - list all shares, export to spreadsheet, don't include default shares
I'm trying to write a script that will list all shares on all drives
Then ignore the default shares: $ADMIN, Apps$, C$, IPC$, Sys$ and only report (send email and dump to spreadsheet) the shares other than this.
Also trying to have this run locally on each computer and send email only when computer is detected to be authenticated to the domain it's on.
Here is what I have so far, any help is appreciated.
Dim sSysDrive : sSysDrive = CreateObject( "Scripting.FileSystemObjec t" ) _
.GetDriveName( _
CreateObject( "WScript.Shell" ).Environment( "PROCESS" )( "SYSTEMROOT" ) )
Dim strComputer : strComputer = "."
Dim objWMIService : Set objWMIService = GetObject( "winmgmts:" _
& "{impersonationLevel=imper sonate}!\\ " & strComputer & "\root\cimv2" )
Dim colDisks
Set colDisks = objWMIService.ExecQuery("S elect * from Win32_LogicalDisk")
Dim drives : drives = ""
Dim objDisk
For Each objDisk in colDisks
wscript.echo objdisk.drivetype &" "&objDisk.DeviceID
If objDisk.DriveType = 3 And objDisk.DeviceID <> sSysDrive Then
If drives > "" Then
drives = drives & ";"
End If
drives = drives & objDisk.DeviceID & "\"
End if
Next
Set colShares = objWMIService.ExecQuery("S elect * from Win32_Share")
For each objShare in colShares
' Wscript.Echo "Allow Maximum: " & objShare.AllowMaximum
' Wscript.Echo "Caption: " & objShare.Caption
' Wscript.Echo "Maximum Allowed: " & objShare.MaximumAllowed
Wscript.Echo "Name: " & objShare.Name
Wscript.Echo "Path: " & objShare.Path
' Wscript.Echo "Type: " & objShare.Type
Next
WScript.Echo drives
Then ignore the default shares: $ADMIN, Apps$, C$, IPC$, Sys$ and only report (send email and dump to spreadsheet) the shares other than this.
Also trying to have this run locally on each computer and send email only when computer is detected to be authenticated to the domain it's on.
Here is what I have so far, any help is appreciated.
Dim sSysDrive : sSysDrive = CreateObject( "Scripting.FileSystemObjec
.GetDriveName( _
CreateObject( "WScript.Shell" ).Environment( "PROCESS" )( "SYSTEMROOT" ) )
Dim strComputer : strComputer = "."
Dim objWMIService : Set objWMIService = GetObject( "winmgmts:" _
& "{impersonationLevel=imper
Dim colDisks
Set colDisks = objWMIService.ExecQuery("S
Dim drives : drives = ""
Dim objDisk
For Each objDisk in colDisks
wscript.echo objdisk.drivetype &" "&objDisk.DeviceID
If objDisk.DriveType = 3 And objDisk.DeviceID <> sSysDrive Then
If drives > "" Then
drives = drives & ";"
End If
drives = drives & objDisk.DeviceID & "\"
End if
Next
Set colShares = objWMIService.ExecQuery("S
For each objShare in colShares
' Wscript.Echo "Allow Maximum: " & objShare.AllowMaximum
' Wscript.Echo "Caption: " & objShare.Caption
' Wscript.Echo "Maximum Allowed: " & objShare.MaximumAllowed
Wscript.Echo "Name: " & objShare.Name
Wscript.Echo "Path: " & objShare.Path
' Wscript.Echo "Type: " & objShare.Type
Next
WScript.Echo drives
ASKER
Thank you. Any idea how I could get the other shares excluded along with the admin shares? IPC$ and Sys$ for example?
This is excluding all Administrative shares; namely:
-saige-
- Disk Drive Admin (2147483648)
- Examples - ADMIN$, C$, D$, E$
- Print Queue Admin (2147483649)
- Device Admin (2147483650)
- IPC Admin (2147483651)
- Examples - IPC$
-saige-
ASKER
Yes, it excludes Administrative shares, but to recognize other shares I would need different method correct?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you so much, exactly what I was looking to do!
ASKER
One more question, how would I get the output "Name:" and "Path" to output and send via email?
Thank you
Thank you
ASKER
Much appreciated!!!
Open in new window
Produces the following results -The Type values were retrieved from here: Win32_Share class
-saige-