【问题标题】:Set folder permissions with PowerShell in different cultures在不同文化中使用 PowerShell 设置文件夹权限
【发布时间】:2018-02-02 16:11:42
【问题描述】:

我正在尝试创建一个 PowerShell 脚本,该脚本将文件夹权限授予不同文化的 NETWORK SERVICE。主要问题是网络服务虽然存在于所有 Windows 安装中,但在不同文化中具有不同的名称,我不知道如何处理。

这是我正在使用的脚本:

$appPath = "C:\SomeFolder"

$Acl = (Get-Item $appPath).GetAccessControl('Access') 

$Ar = New-Object System.Security.AccessControl.FileSystemAccessRule("NETWORK SERVICE", "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow")

$Acl.SetAccessRule($Ar)

Set-Acl $appPath $Acl

现在这个脚本在英文版的 Windows 上运行良好。但是,当尝试在德语版本的 Windows 上运行它时,我收到以下错误消息(翻译自德语):

使用“1”参数调用“SetAccessRule”的异常:“部分或全部身份 无法翻译参考文献。” 在 C:\Experimental Files\GrantFolderPermissions.ps1:7 char:1 + $Acl.SetAccessRule($Ar) + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : IdentityNotMappedException

我怎样才能最好地处理这个问题,以便这个脚本能够独立地工作?

【问题讨论】:

标签: windows powershell culture folder-permissions


【解决方案1】:

使用well-known SID 确定帐户名称:

$sid = [Security.Principal.SecurityIdentifier]'S-1-5-20'
$acct = $sid.Translate([Security.Principal.NTAccount]).Value

$ace = New-Object Security.AccessControl.FileSystemAccessRule($acct, 'FullControl', 'ContainerInherit,ObjectInherit', 'None', 'Allow')

【讨论】:

    猜你喜欢
    • 2023-03-28
    • 2012-12-26
    • 1970-01-01
    • 2017-05-31
    • 2014-09-28
    • 1970-01-01
    • 2012-01-20
    • 2015-10-18
    • 1970-01-01
    相关资源
    最近更新 更多