使用 PowerShell 在磁盘管理中设置卷的权限

问题描述 投票:0回答:1

我向服务器提供了一些 SAN 存储,并使用 Windows 中的磁盘管理创建了一个挂载点。事实证明,对该文件夹的 SQL 服务帐户的权限不够,还必须从磁盘管理中设置权限(在磁盘管理中选择卷上的属性,然后向 SQL 服务帐户授予权限)。

我使用下面的代码来设置文件夹的权限。是否有等效的 PowerShell 方法来设置卷/磁盘的权限?正如人们可以在磁盘管理的 GUI 中所做的那样。

$NewAcl = Get-Acl -Path "E:\Data\LUN" 
# Set properties
$identity = "Domain\user"
$fileSystemRights = "FullControl"
$type = "Allow"
# Create new rule
$fileSystemAccessRuleArgumentList = $identity, $fileSystemRights, $type
$fileSystemAccessRule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $fileSystemAccessRuleArgumentList
# Apply new rule
$NewAcl.SetAccessRule($fileSystemAccessRule);
Set-Acl -Path "E:\Data\LUN" -AclObject $NewAcl;
powershell permissions acl mount-point san
1个回答
0
投票

在磁盘管理 GUI 中执行 ACL 更改与将更改应用于驱动器的根目录相同,并启用对象和容器继承标志。这非常冗长,但实际上是这样的:

$Rights = [System.Security.AccessControl.FileSystemRights]"FullControl" 

$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]"ObjectInherit,ContainerInherit"
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None 

$objType =[System.Security.AccessControl.AccessControlType]::Allow 

$objUser = New-Object System.Security.Principal.NTAccount("Domain\user") 

$objACE = New-Object System.Security.AccessControl.FileSystemAccessRule($objUser, $Rights, $InheritanceFlag, $PropagationFlag, $objType) 

$objACL = Get-ACL "E:" 

$objACL.AddAccessRule($objACE) 

Set-ACL "E:" $objACL
© www.soinside.com 2019 - 2024. All rights reserved.