PowerShell for Windows Admins

Mar 6 2010   4:37AM GMT

Sharing



Posted by: Richard Siddaway
Tags:
PowerShell v2
Shares
WMI

 

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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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: