使用powershell将带有换行符的InheritanceFlags输出到csv文件中

时间:2018-03-05 14:02:22

标签: excel powershell powershell-v3.0

我正在开发一个PowerShell脚本,它将所有NTFS文件夹权限导出到CSV文件。它工作正常,但我想以某种方式输出,我无法实现。这是代码:

$OutFile = "C:\Permissions.csv"
$Header = "Folder Path,IdentityReference,AccessControlType,IsInherited,InheritanceFlags,PropagationFlags"
Del $OutFile
Add-Content -Value $Header -Path $OutFile 

$RootPath = "C:\Test"

$Folders = dir $RootPath -Recurse | where {$_.PSIsContainer -eq $true}

foreach ($Folder in $Folders) {
    $ACLs = Get-Acl $Folder.FullName | ForEach-Object { $_.Access }
    foreach ($ACL in $ACLs) {
        $OutInfo = $Folder.FullName + "," + $ACL.IdentityReference  + "," +
                   $ACL.AccessControlType + "," + $ACL.IsInherited + "," +
                   $ACL.InheritanceFlags + "," + $ACL.PropagationFlags
        Add-Content -Value $OutInfo -Path $OutFile
    }
}

目前正以这种方式产生输出。

https://drive.google.com/open?id=1KwWdX42zyX-EoMHciwSEOuSCzcQu315d

唯一的问题是$ACL.InheritanceFlags使用逗号输出两个值,一个是 ContainerInherit ,另一个是 ObjectInherit 。由于逗号,值会转移到新单元格,因此它会落入PropagationFlags单元格中。

我希望InheritanceFlags值在一个单元格中,但是像这样有一个换行符。

https://drive.google.com/open?id=1QcZX6GmZvW2xot5hcZTMVuj4iHnzmj8Y

我尝试使用此`n,但它不会改变任何内容。有没有办法实现这个目标?

0 个答案:

没有答案
相关问题