Powershell Script for creating file shares.

	#Username/Group to give permissions to
	$trustee = ([wmiclass]‘Win32_trustee’).psbase.CreateInstance()
	$trustee.Domain = “csinet”
	$trustee.Name = “Everyone”

	#Accessmask values
	$fullcontrol = 2032127
	$change = 1245631
	$read = 1179785

	#Create access-list
	$ace = ([wmiclass]‘Win32_ACE’).psbase.CreateInstance()
	$ace.AccessMask = $fullcontrol
	$ace.AceFlags = 3
	$ace.AceType = 0
	$ace.Trustee = $trustee

	#Securitydescriptor containting access
	$sd = ([wmiclass]‘Win32_SecurityDescriptor’).psbase.CreateInstance()
	$sd.ControlFlags = 4
	$sd.DACL = $ace
	$sd.group = $trustee
	$sd.owner = $trustee

	$share = Get-WmiObject Win32_Share -List -ComputerName “csidfs01-vm”
	$share.create(“e:\wupdate”, “wupdate”, 0, 1000, “Description”, “”, $sd)
	#$share.create(“e:\ApplicationData”, “ApplicationData”, 0, 1000, “Description”, “”, $sd
	#$share.create(“e:\Desktop”, “Desktop”, 0, 1000, “Description”, “”, $sd
	$share.create(“e:\DiskImage”, “DiskImage”, 0, 1000, “Description”, “”, $sd)
	#$share.create(“e:\Documents”, “Documents”, 0, 1000, “Description”, “”, $sd
	$share.create(“e:\Profiles”, “Profiles”, 0, 1000, “Description”, “”, $sd)
	$share.create(“e:\Shares”, “Shares”, 0, 1000, “Description”, “”, $sd)
	$share.create(“e:\TS-ApplicationData”, “TS-ApplicationData”, 0, 1000, “Description”, “”, $sd)
	$share.create(“e:\TS-Desktop”, “TS-Desktop”, 0, 1000, “Description”, “”, $sd)
	$share.create(“e:\TS-Documents”, “TS-Documents”, 0, 1000, “Description”, “”, $sd)

Jeremy Tirrell

Read more posts by this author.