使用 PowerShell 共享文件夹的权限
Permissions on shared folder with PowerShell
我需要将“Everyone”的权限设置为 Change 和 Read共享文件夹上的 PowerShell。我不知道怎么做,你能帮我吗?
- 我是 运行宁 windows 服务器 2008
以下代码在 Windows Server 2012 上运行良好。我需要在 Windows Server 2008 上 运行 它:
[WMICLASS]"Win32_Share"|%{$_.Create($path,$sharefoldername,0)} | Out-Null
Grant-SmbShareAccess -name $sharefoldername -CimSession $Server -AccountName Everyone -AccessRight Change –Force | Out-Null
查看 SmbShare cmdlet:
Import-Module SmbShare
Get-Command -Noun Smb*
对于现有共享,您可以使用 Grand-SmbShareAccess,您可以使用 Get-Help 获取一些使用示例。
Get-Help Grant-SmbShareAccess -Examples
我找到的有效答案是这样的:
#Username/Group to give permissions to
$trustee = ([wmiclass]'Win32_trustee').psbase.CreateInstance()
$trustee.Domain = $null
$trustee.Name = "Everyone"
#Accessmask values
#$fullcontrol = 2032127
$change = 1245631
#$read = 1179785
#Create access-list
$ace = ([wmiclass]'Win32_ACE').psbase.CreateInstance()
$ace.AccessMask = $change
$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 $server
$share.create($advsharing, $sharefoldername, 0, "16777216", "Description"", $sd)
我需要将“Everyone”的权限设置为 Change 和 Read共享文件夹上的 PowerShell。我不知道怎么做,你能帮我吗?
- 我是 运行宁 windows 服务器 2008
以下代码在 Windows Server 2012 上运行良好。我需要在 Windows Server 2008 上 运行 它:
[WMICLASS]"Win32_Share"|%{$_.Create($path,$sharefoldername,0)} | Out-Null
Grant-SmbShareAccess -name $sharefoldername -CimSession $Server -AccountName Everyone -AccessRight Change –Force | Out-Null
查看 SmbShare cmdlet:
Import-Module SmbShare
Get-Command -Noun Smb*
对于现有共享,您可以使用 Grand-SmbShareAccess,您可以使用 Get-Help 获取一些使用示例。
Get-Help Grant-SmbShareAccess -Examples
我找到的有效答案是这样的:
#Username/Group to give permissions to
$trustee = ([wmiclass]'Win32_trustee').psbase.CreateInstance()
$trustee.Domain = $null
$trustee.Name = "Everyone"
#Accessmask values
#$fullcontrol = 2032127
$change = 1245631
#$read = 1179785
#Create access-list
$ace = ([wmiclass]'Win32_ACE').psbase.CreateInstance()
$ace.AccessMask = $change
$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 $server
$share.create($advsharing, $sharefoldername, 0, "16777216", "Description"", $sd)