PowerShell for Windows Admins

Mar 6 2010   4:37AM GMT

Sharing

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

 

One area of our Windows machines that we definitely need to think about is the shares we create on a machine. These control access to resources – especially file resources.

We can find the shares on a machine using the Win32_Share class. The name of the share and its path together with a description form the default display.

Remember we can use the –computername parameter to access remote machines. I tend not to use it in these posts to keep the script lengths down.

PS> Get-WmiObject -Class Win32_Share | Format-Table -AutoSize

Name            Path                              Description
—-            —-                              ———–
ADMIN$          C:\Windows                        Remote Admin
C$              C:\                               Default share
D$              D:\                               Default share
HP DeskJet 812C HP DeskJet 812C,LocalsplOnly      HP DeskJet 812C
IPC$                                              Remote IPC
print$          C:\Windows\system32\spool\drivers Printer Drivers
Test            C:\Test
Users           C:\Users

Next move is to find what we can do with them.

PS> Get-WmiObject -Class Win32_Share | Get-Member -MemberType method | select name

Name
—-
Delete
GetAccessMask
SetShareInfo

shows three methods.  Delete and SetShareInfo we can perform by using the cmdlets Remove-WmiObject and Set-WmiInstance respectively.

What does GetAccessMask do for us?

$share = Get-WmiObject -Class Win32_Share -Filter "Name=’Test’"

PS> $share.GetAccessMask()

__GENUS          : 2
__CLASS          : __PARAMETERS
__SUPERCLASS     :
__DYNASTY        : __PARAMETERS
__RELPATH        :
__PROPERTY_COUNT : 1
__DERIVATION     : {}
__SERVER         :
__NAMESPACE      :
__PATH           :
ReturnValue      : 2032127

Next we need to unravel this return value

Technorati Tags: ,,

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: