powershell - 文件夹权限的 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
我检查了所有变量,但我仍然有这个问题。有人可以帮忙吗?
解决方案
推荐阅读
- sql - 在简单 SQL 语句中使用 NOT LIKE 时的奇怪行为
- go - 如何执行动态解组
- memory - 如何在 Flutter Android 生产应用程序中获取可用和已分配内存的大小?
- google-apps-script - FOR 循环迭代停止在某个数字
- python - 复制元组值以在 python 中创建随机数据集
- laravel - 如果已经批准,如何将按钮更改为徽章?
- php - CORS 预检请求未通过访问控制检查:它没有 HTTP ok 状态
- unicode - 显示不带虚线环的变音符号
- angularjs - 我有一个 15 到 30 个坐标的列表。给定任何 X,Y 坐标,从前端找到列表中最近坐标的方法是什么?
- django - 如何检查用户电子邮件是否已保存在数据库中