PowerShell Scripting - WmiObject Win32_SharePowerShell Scripting - WmiObject Win32_ShareThe 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-WmiObjectI 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 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_share1) Initial Investigation To display a list of all the objects properties, never miss an
opportunity to employ: 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 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 LANSurveyor
|
||||||
Download my ebook:
|
*
|
|
|
|
Home Copyright © 1999-2009 Computer Performance LTD All rights reserved Please report a broken link, or an error. | |