首页 > 解决方案 > 文件夹权限的 Powershell Null 值

问题描述

我有以下PowerShell代码:

''''

$Rights = "FullControl" #Comma seperated list, 2 rows, user and path.
$InheritSettings = "ContainerInherit, ObjectInherit" #Controls how permissions are inherited by children
$PropogationSettings = "None" #Usually set to none but can setup rules that only apply to children.
$RuleType = "Allow" #Allow or Deny.
$csv = Import-CSV "C:\scripts\test.csv" -delimiter ","
ForEach ($line in $csv) {
    $acl = Get-Acl $line.path
    $user = ('LSS\' + $line.user)

    $perm = $user, $Rights, $InheritSettings, $PropogationSettings, $RuleType
    $rule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $perm
    $acl.SetAccessRule($rule)
    $acl | Set-Acl -Path $path
} 

我不断收到以下错误:

You cannot call a method on a null-valued expression.
At line:12 char:5
+     $acl.SetAccessRule($rule)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

我检查了所有变量,但我仍然有这个问题。有人可以帮忙吗?

标签: powershell

解决方案


推荐阅读