PowerShell Ezine, Logon Scripts

 

Contact Guy
About Us
Affiliate Program
MCSE Exams
Guy's eBooks
Advice Payment

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

Computer Training Software - Recommended Training VideosGuy Thomas recommends Computer Training Software

Their topics and material are ideal for getting you started with VBScript.  The videos are easy to follow and you can control the pace.  Try their free demo material and then see if you want to buy the full package. See more about VB Script Training CD.


 *


Google

Web  This website

Review of Orion NPMGuy Recommends: Orion's NPM - Network Performance Monitor

Orion's performance monitor is designed for detecting network outages. A network-centric view make it easy to see what's working, and what needs your attention.

This utility guides you through troubleshooting by indicating whether the root cause is faulty equipment or resource overload.

Download a free trial of the Network Performance Monitor

 

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

Please report a broken link, or an error.