PowerShell Ezine, Logon Scripts

Guy's Scripting Ezine 75 -  List a Computers Shares, Out-Takes

Contents for Ezine 75 List Shares - Out-takes

  1. This Week's Secret
  2. This Week's Mission - To Display Network Shares
  3. Example 1 - To Map to Display Network Shares
  4. Example 2 - To Map to Display Network Shares

This Week's Mission - To Display Network Shares

What this week's script will do is to display shared folders and printers.  In the first example, we have to hard-code the name of the server in the script itself.  The second script not only provides an inputbox for you to interrogate different servers, but also lists the shares in one long list.  The first example is easy scripting but laboriously echoes each share in turn.  It drove me mad because I had to keep clicking OK on each share's message box.  The second share builds up a list of all shares then displays them all in one long list.

Start - Check the basic scripts

I suggest that you start with the working scripts, then try and correct these mistakes.

Out-take 1 - To Map to Display Network Shares

Here is a simple script, which should interrogate a servers operating system, and then echo each shared folder or shared printer.

Instructions for displaying a servers shares

  1. Copy and paste the script below into notepad.
  2. Double click the script, then read the names of the shares in the message box.

 

' ListShare.vbs Windows Logon Script
' VBScript List Shares on a Server
' Author Guy Thomas http://computerperformance.co.uk/
' Ezine 75 Out-Take 1.2 - May 2005
' ----------------------------------------------------'
Option Explicit
Dim objFs, objShare
Dim strServer

' The section sets the variables
strServer = "GuyServer"

' Connects to the operating system's file system
set objFs = GetObject("WINNT://" _
& strServer & "/LanmanServer,FileService")

' Loops through each share
For Each objShare In objFs
WScript.Echo objShare.name
Next

End of List Share VBScript

Learning Points for Listing Shares

Note 1:  Pay attention to case sensitive words.

Out-Take 2 - To Map to Display Network Shares

 

' ListShare.vbs Windows Logon Script
' VBScript List Shares on a Server
' Author Guy Thomas http://computerperformance.co.uk/
' Ezine 75 Out-Take 2.3 - May 2005
' ----------------------------------------------------'
Option Explicit

Dim objFs, objShare
Dim strServer, strList

' The section sets the variables
strList = " --------------------------- "
strServer = "alan"

' Creates the Input Message Box
strServer = InputBox("Server to list shares: "_
," Share List", strServer)

' Connects to the operating system's file system
set objFs = GetObject("WinNT://" _
& strServer & "/LanmanServer,FileService")

' Loops through each share
For Each objShare In objFs
strList = strList & vbCr & LCase(objShare) _
& " " & vbTab & UCase(objShare.Description)
Next

WScript.Echo strList

End of List Share VBScript


Learning Points for Example 2

Note 1: Review the Object, Property syntax.

Answers

Out-Take 1.  Should be WinNT not WINNT

Out-Take 2.  You need the name property, objShare.name not objShare

See more about logon scripts

MapNetworkDrive  • Ezines  • Logon Map Network Drive  • Logon Scripts  • LEM 

Ezine 32 Remove  • Ezine 60 Rename  • PowerShell Logon Scripts  • Ezine 74 Map

Ezine 75 Shares  • Ezine 87 Map drive  • Ezine 105 Map Arguments  

Ezine 115 Map Groups  • Ezine 132 Assign Logon  • Tool Kit  • Free CSV Importer


Custom Search

Guy Recommends: WMI Monitor and It's Free!Solarwinds WMI Monitor

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft operating systems.

Fortunately, Solarwinds have created the Free WMI Monitor so that you can actually see and understand these gems of operating system information.  Take the guess work out of which WMI counters to use for scripts.

Download your free copy of WMI Monitor

 

Home Copyright © 1999-2012 Computer Performance LTD All rights reserved

Please report a broken link, or an error.