powershell - 将每个唯一的文件系统写在新行上 | 电源外壳
问题描述
我正在创建一个 PowerShell 脚本,它将对目录中所有文件夹启用的权限写入 CSV 文件以进行报告。此报告的要求是文件系统权限必须分别位于单独的行上,而不是全部位于一行上(我的代码目前就是这样做的)。例如,当前这些权限如下所示:
C:/temp-folder_123 (column) ReadData- ExecuteFile- Synchronize
但我希望它的格式如下:
C:/temp-folder_123 (column) ReadData
C:/temp-folder_123 (column) ExecuteFile
C:/temp-folder_123 (column) Synchronize
这是我的代码:
foreach ($access_right in $acl.Access)
{
if ( ($access_right.FileSystemRights -notmatch $exclude_filesystem_rightss_regex) )
{
$file_stream_output.WriteLine(('{0}, {1}, {2}' -f $directory.FullName, $access_right.IdentityReference, ($access_right.FileSystemRights -replace ",","-" )))
}
解决方案
要拆分 .FileSystemRights 您必须使用另一个 ForEach 对其进行迭代
foreach ($access_right in $acl.Access) {
if (($access_right.FileSystemRights -notmatch $exclude_filesystem_rightss_regex) ){
foreach($fsr in $access_right.FileSystemRights){
$file_stream_output.WriteLine(('{0}, {1}, {2}' -f `
$directory.FullName,
$access_right.IdentityReference,
$fsr)
}
)
}
推荐阅读
- c# - AKS 中的 EF Core DbContext 错误,但不在容器中本地
- encryption - Aurora - 存储桶加密时从 s3 加载数据
- python - 如何与 chrome 扩展进行交互?
- docker - aerospike:Docker 容器中无法识别的服务?
- javascript - Chrome 扩展 - 如何使用 JavaScript 在 A 扩展的 B 扩展的选项页面字段中粘贴值
- python - 如何使用文本小部件中插入的某个问题并检查用户是否回答是或否?
- php - 在php中计算数组中具有相同名称的元素
- linux - javax.net.ssl.SSLException:收到致命警报:protocol_version,Java1.8.0_201 使用 TLSv1 而不是默认的 TLSv1.2 进行握手
- python - 如何根据记录中其他 4 个字段的布尔运算符有效地更新数据框中的字段?
- ios - pushViewController 无法执行 segue