我正在尝试创建PowerShell脚本,该脚本将文件夹权限授予不同区域性上的网络服务。主要的问题是,网络服务虽然存在于所有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上运行时,我收到以下错误消息(翻译自德语):
Exception calling "SetAccessRule" with "1" argument(s): "Some or all identity
references could not be translated."
At C:\Experimental Files\GrantFolderPermissions.ps1:7 char:1
+ $Acl.SetAccessRule($Ar)
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : IdentityNotMappedException
我如何才能最好地处理这个问题,使这个脚本能够独立于文化环境工作?