PowerShell for Windows Admins

Apr 2 2010   11:14AM GMT

Shares: Discovering



Posted by: Richard Siddaway
Shares

 

As I said last time I’ve modified the Get-Share function to accept a share name.

001
002
003
004
005
006
007
function Get-Share {
param (
    [string]$name
)   
    if (!$name) {Get-WmiObject -Class Win32_Share}
    else {Get-WmiObject -Class Win32_Share -Filter "Name=’$name’"}
}

if a name isn’t provided that all shares are returned.  If we supply a name only that share is returned. In either case we can put the object onto the pipeline and perform further processing.

Get-Share | ft name, maximumallowed, description

Get-Share -name test1 | fl name, maximumallowed, description

Comment on this Post

Leave a comment: