【发布时间】:2021-11-02 01:21:02
【问题描述】:
Powershell 相当新。我正在尝试将一些不同的概念应用于此解决方案。
我想创建一个文件夹,然后使用旨在帮助将 ACL 设置为文件夹的函数。一个多维数组,用于保存用于各种目的和部门的文件夹名称模板。数字只是占位符。
我运行假设添加,我没有收到任何错误,但感觉就像我在某个地方犯了错误。
我在 Powershell 中研究了很多循环和迭代多维数组,但没有找到与我的意图非常匹配的内容。
function Set-permissions {
Param($assign_to_Read, $assign_to_RW, $path)
#Create new ACL Object
$acl_main = New-Object System.Security.AccessControl.DirectorySecurity
#Create Read Object
$ACL_Read = New-Object System.Security.AccessControl.FileSystemAccessRule($assign_to_Read, "Read", "Allow")
#Set first access object to ACL: Read
$acl_main.SetAccessRule($ACL_Read)
#Create Modify Object
$ACL_RW = New-Object System.Security.AccessControl.FileSystemAccessRule($assign_to_RW, "Modify", "Allow")
#Add access object to ACL: Modify
$acl_main.AddAccessRule($ACL_RW)
#Pipe the
$acl_main | Set-Acl -Path $path -WhatIf
}
New-Item -Path $top_level -Name $result -ItemType "directory"
#Create Subdirectories and Assign Read and RW ACL
$newEmployeePath = $top_level + '\' + $result
$employee_template = @(
("1 ",
"ACL_Read_1 ",
"ACL_RW_1 "),
("2 ",
"ACL_Read_2 ",
"ACL_RW_2 "),
("3 ",
"ACL_Read_3 ",
"ACL_RW_3 "),
)
ForEach($folder in $employee_template ){
#Create the Folder from first location in the array
New-Item -Path $newEmployeePath -Name $folder[0]
#Set permissions for Read and RW on the folder.
Set-permissions $folder[1] $folder[2] $newEmployeePath
}
}
【问题讨论】:
-
我们还没有收到您的来信。我的回答解决了您的问题吗?如果是这样,请通过单击左侧的 ✓ 图标来考虑accepting。这将帮助其他有类似问题的人更轻松地找到它,并有助于激励其他人回答您将来可能遇到的任何问题。
标签: arrays powershell multidimensional-array acl