我有以下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
我已经检查了所有变量,但是仍然有这个问题。有人可以协助吗?