# Set-ShareInfo.msh
# Sets the security of a Share
# /\/\o\/\/ 2005
# get the needed WMI Classes
$sd = new-object system.management.managementclass Win32_SecurityDescriptor
$ace = new-object system.management.managementclass Win32_ace
$Trustee = new-object system.management.managementclass win32_trustee
# Make AccessMask
# this are the values, With Change and Read (you need to add Synchronize Also if using the FileSystemRights)
# (so maybe better to just use the list of Integers,I leave the FileSystemRights in for reference).
# 2032127 "Full"
# 1245631 "Change"
# 1179817 "Read"
$mode = "Change"
switch ($mode) {
"Full" {$AM = ([System.Security.AccessControl.FileSystemRights]"FullControl").Value__}
"Read" {$AM = ([System.Security.AccessControl.FileSystemRights]"ReadAndExecute").Value__ + ([System.Security.AccessControl.FileSystemRights]"Synchronize").Value__}
"Change" {$AM = ([System.Security.AccessControl.FileSystemRights]"Modify").Value__ + ([System.Security.AccessControl.FileSystemRights]"Synchronize").Value__}
}
# Make the Trustee
$Trustee.Domain = $Null
$Trustee.Name = "Everyone"
#Still looking for A way to get this from text SID (setting SIDstring will not work)
# the SID has a function but I don't know how to do a ByRef in MSH
# $sid.GetBinaryForm($global:ba,0), for now do it by hand.
$Trustee.SID = @(1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0)
$ace.AccessMask = $AM
# AceType Value Meaning
# 0 Access Allowed
# 1 Access Denied
# 2 Audit
$ace.AceType = 0
$ace.AceFlags = 3
$ace.trustee = $trustee.mshobject.baseobject
# add the ACE(s) to the DACL
$SD.DACL = @($ACE.mshobject.baseobject)
#get the Share
$share = get-wmiObject win32_share -filter "name='mp3'"
$inparams = $share.GetMethodParameters("setShareInfo")
#set parameters
#$inParams["Description"] = "test"
$inParams["Access"] = $SD.mshobject.baseobject
#Write back
$share.invokemethod("setshareInfo",$inparams,$null)
October 2005 November 2005 December 2005 January 2006 February 2006 March 2006 April 2006 May 2006 June 2006 July 2006 August 2006 September 2006 October 2006 November 2006 December 2006