Guy recommends :
Free Solarwinds
VM Console

Solarwinds VM Console Free Download

Find out which of your VMs are a waste of space and which VMs need more resources.



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 "*$"}

Solarwinds Network Device MonitorGuy Recommends Solarwinds' Free Network Monitor

Thus utility makes it easy to check the health of a router or firewall.  Check the real-time performance, and availability statistics, for any device on your network.  Get started with an extensive collection of "out-of-the-box" monitors for popular network devices. 

Download your free Network Device Monitor

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.

If you like this page then please share it with your friends

 


See more PowerShell share examples including WMI

PowerShell WMI   • Win32_Share   • WMI Shares   • Query

Get-Acl  • PowerShell Error Codes   • Win32_ComputerSystem

Please email me if you have a example scripts. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.

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.

 *


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 performance information.  Take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.

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.