Windows PowerShell


PowerShell Scripting - WmiObject Win32_Share

PowerShell Scripting - WmiObject Win32_Share

The purpose of this script is to list shares on a server.  In fact, this code will enumerate the shares on any computer.

WMI and PowerShell Topics

 ♣

Preliminary: Get-WmiObject

I admit that there is a danger of getting side tracked when we start experimenting with these command.  My justification is that research WMI properties is useful in other contexts.

Get-WmiObject -list
or even
Get-WmiObject -list |where {$_.name -like "win32*"}

Note 1: See how the production line is controlled by the pipe | in the middle.

Note 2: Remember that 'where' {takes curly brackets}. 

Note 3: Observe that 'like' is a parameter or switch, thus needs a minus sign: -like.

Five Examples of WmiObject win32_share

1) Initial Investigation

To display a list of all the objects properties, never miss an opportunity to employ:
get-Member

Get-WmiObject win32_share | Get-Member

2) Basic

Get-WmiObject win32_share

3) Switch to a named server

Get-WmiObject win32_share -computer YourBigServer

Note: Naturally, change the name of YourBigServer to the name of a machine on your subnet.

4) Filter Properties Path, then Name, but NO Description

WmiObject win32_share | ft path, name -autosize

Note: Redundant Option removed: (Get-)WmiObject
Note: ft means format-Table.  Other options are format-list or format-custom.

5) Display Shares, which are not hidden

WmiObject win32_share | Where {$_.name -notlike "*$"} | sort-Object -property path | ft path, name -autosize

Note1: Strictly speaking the term is where-Object, however, I removed the redundant noun -object.  You could also try omitting '-object' from 'sort-Object

Challenge: Try: Where {$_.name -like "*$"}

Guy Recommends: SolarWinds LANSurveyorSolarwinds LANSurveyor

LANSurveyor will produce a neat diagram of your network topology.  But that's just the start; LANSurveyor can create an inventory of the hardware and software of your machines and network devices.  Other neat features include dynamic update for when you add new devices to your network.  I also love the ability to export the diagrams to Microsoft Visio.

Finally, Guy bets that if you take a free trial of LANSurveyor then you will find a device on your network that you had forgotten about, or someone else installed without you realizing!

Download a Free Trial of LANSurveyor

Summary of Scripting PowerShell Shares

Firstly, remember that win32_share is a WmiObject.  Secondly, once you have mastered the basics you may wish to filter the shares by using a 'Where' statement.  Finally, you may wish to modify the number and position of the properties displayed in the output.

See more Microsoft PowerShell examples of WMI

PowerShell Home   • WMI   • Service   • WMI File   • WMI Query   • DNS   • Disk

Classes   • Network Adapter   • PowerShell WMI examples

Please write in if you see errors of any kind.  Please report any factual mistakes, grammatical errors or broken links, I will be happy to not only to correct the fault, but also to give you credit.

Download my ebook:Getting Started with PowerShell
Getting Started with PowerShell - only $9.25

You get 36 topics organized into these 3 sections:
   1) Getting Started
   2) Real-life tasks
   3) Examples of Syntax.

In addition to the ebook, you get a PDF version of this  Introduction to PowerShell ebook  It runs to 120 pages of A4.

 *


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-2009 Computer Performance LTD All rights reserved

Please report a broken link, or an error.