Guy recommends:
A free trial of

Solarwinds Free WebHelpDesk

Install a ticket-based help desk system from SolarWinds. Download your free trial

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 Task: 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.

# Research WMI Classes
Get-WmiObject -List
or even
Get-WmiObject -List | Where {$ -Like "win32*"}

Note 1: See how the production line of classes 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 research properties with 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 4: Naturally, change the name of YourBigServer to the name of a machine on your subnet.

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

Get-WmiObject Win32_share | FT path, name -autosize

Note 5: FT is an alias of Format-Table.  Other options are format-List or format-custom.

Guy Recommends: Free WMI Monitor for PowerShellSolarwinds Free WMI Monitor for PowerShell

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft's operating systems.  Fortunately, SolarWinds have created a Free WMI Monitor so that you can discover these gems of performance information, and thus improve your PowerShell scripts.

Take the guess work out of which WMI counters to use when scripting the operating system, Active Directory, or Exchange Server. Give this WMI monitor a try - it's free.

Download your free copy of WMI Monitor

5) Display Shares, which are not hidden ($)

WmiObject Win32_share | Where {$ -NotLike "*$"} | `
Sort-Object -property path | FT path, name -autosize

Note 6: 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 {$ -Like "*$"}

How to create a share with PowerShell »

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   • Create Win32_Share   • WMI Shares   • Free Permissions Analyzer Tool

Get-Acl  • PowerShell Share Error Codes   • Win32_ComputerSystem  • PowerShell 3.0 CIM

Windows PowerShell  • Free WMI Monitor  • Cacls   • Query   • PowerShell Printer Scripts

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.



Custom Search

Site Home

Guy Recommends: WMI Monitor for PowershellSolarwinds WMI Monitor

Windows Management Instrumentation (WMI) is most useful for PowerShell scripting.

SolarWinds have produced this Free WMI Monitor to 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

Author: Guy Thomas Copyright © 1999-2017 Computer Performance LTD All rights reserved.

Please report a broken link, or an error to: