为AD2003编写脚本共享安全和NTFS设置

我们将使用SCCM部署“dynamic”教室,因此还需要创buildOU和匹配的用户和家庭。 我目前正在试图找出如何通过脚本编辑这些homedirs的安全权限。 我使用谷歌有限的成功,因为很多看起来过时了,所以我想看看什么ServerFault认为是最好的方式。

我需要做的是: – 创build文件夹(不是问题) – 共享并设置权限为所有人完全控制 – 将NTFS设置更改为单个用户的“更改”或“修改”

脚本的其他部分目前是用vbscript完成的,但是如果需要的话,我明显可以从这个脚本中调用不同的脚本。 PowerShell可能是一个select(如果可能的话),但我也渴望听到其他的select!

谢谢

这是一个PowerShell脚本,它可以做你想做的事情。

$Computer = "localhost" $Class = "Win32_Share" $Method = "Create" $name = "foldername$" $path = "C:\Folderpath" $description = "This is shared for me to test" $sd = ([WMIClass] "\\$Computer\root\cimv2:Win32_SecurityDescriptor").CreateInstance() $ACE = ([WMIClass] "\\$Computer\root\cimv2:Win32_ACE").CreateInstance() $Trustee = ([WMIClass] "\\$Computer\root\cimv2:Win32_Trustee").CreateInstance() $Trustee.Name = "EVERYONE" $Trustee.Domain = $Null $Trustee.SID = @(1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0) $ace.AccessMask = 2032127 $ace.AceFlags = 3 $ace.AceType = 0 New-Item -type directory -path $path $Acl = Get-Acl $path $Ar = New-Object system.security.accesscontrol.filesystemaccessrule("user\domain","Write","Allow") $Acl.SetAccessRule($Ar) Set-Acl $path $Acl $ACE.Trustee = $Trustee $sd.DACL += $ACE.psObject.baseobject $mc = [WmiClass]"\\$Computer\ROOT\CIMV2:$Class" $InParams = $mc.psbase.GetMethodParameters($Method) $InParams.Access = $sd $InParams.Description = $description $InParams.MaximumAllowed = $Null $InParams.Name = $name $InParams.Password = $Null $InParams.Path = $path $InParams.Type = [uint32]0 $R = $mc.PSBase.InvokeMethod($Method, $InParams, $Null) switch ($($R.ReturnValue)) { 0 {Write-Host "Share:$name Path:$path Result:Success"; break} 2 {Write-Host "Share:$name Path:$path Result:Access Denied" -foregroundcolor red -backgroundcolor yellow;break} 8 {Write-Host "Share:$name Path:$path Result:Unknown Failure" -foregroundcolor red -backgroundcolor yellow;break} 9 {Write-Host "Share:$name Path:$path Result:Invalid Name" -foregroundcolor red -backgroundcolor yellow;break} 10 {Write-Host "Share:$name Path:$path Result:Invalid Level" -foregroundcolor red -backgroundcolor yellow;break} 21 {Write-Host "Share:$name Path:$path Result:Invalid Parameter" -foregroundcolor red -backgroundcolor yellow;break} 22 {Write-Host "Share:$name Path:$path Result:Duplicate Share" -foregroundcolor red -backgroundcolor yellow;break} 23 {Write-Host "Share:$name Path:$path Result:Reedirected Path" -foregroundcolor red -backgroundcolor yellow;break} 24 {Write-Host "Share:$name Path:$path Result:Unknown Device or Directory" -foregroundcolor red -backgroundcolor yellow;break} 25 {Write-Host "Share:$name Path:$path Result:Network Name Not Found" -foregroundcolor red -backgroundcolor yellow;break} default {Write-Host "Share:$name Path:$path Result:*** Unknown Error ***" -foregroundcolor red -backgroundcolor yellow;break} } 

我把它从一些其他的网站, 1和2打了一遍。 它适用于我的Windows 7机器。 有关filesystemaccessrule对象的更多信息,请看这里 。

我爱CMD.EXE …(不是真的):

 mkdir x:\directory\to\make cacls x:\directory\to\make /e /t /g DOMAIN\user:C net share sharename=X:\directory\to\make 

这使得目录,添加“更改”权限的目录(这将inheritance到子文件夹和文件)“DOMAIN \用户”并共享目录。 前两个命令可以针对UNCpath运行,但必须在共享目录所在的服务器上执行net share 。 (在Windows NT资源工具包发行版中有一个旧的rmtshare.exe工具,它具有与net share大致相同的语法,但可以在远程计算机上创build共享。)

应该可以使用命令calcs