gpt4 book ai didi

powershell-3.0 - PowerShell 删除列标题

转载 作者:行者123 更新时间:2023-12-05 08:34:33 24 4
gpt4 key购买 nike

我有以下代码将根路径的文件夹权限导出到 CSV 文件:

$RootPath = "\\R9N2WRN\Test Folder"
$OutFile = "C:\CodeOutput\Permissions.csv"
$Header = "Folder Path,IdentityReference"
Del $OutFile
Add-Content -Value $Header -Path $OutFile

$Folders = dir $RootPath -recurse | where {$_.psiscontainer -eq $true}
foreach ($Folder in $Folders)
{
$ACLs = get-acl $Folder.fullname |
ForEach-Object { $_.Access } |
Where {$_.IdentityReference -notlike "*BUILTIN*" -and $_.IdentityReference -notlike "*NT AUTHORITY*"}
Foreach ($ACL in $ACLs)
{
$OutInfo = $Folder.Fullname + "," + $ACL.IdentityReference
Add-Content -Value $OutInfo -Path $OutFile
}
}

输出文件有列标题“文件夹路径”和“IdentityReference”,因为我想在多个根路径上运行这个脚本,有没有办法摆脱这些列标题与输出一起发送到CSV 文件?

最佳答案

我知道这是一篇旧帖子并且已经得到回答,但我认为这可能对其他人有帮助。

我想做类似的事情,但不想将输出写入文件、读取,然后重新写入。所以我改为这样做:

Your_Data_In_Pipe | ConvertTo-Csv -NoTypeInformation | select -Skip 1 | Set-Content File_Without_Headers.csv

关于powershell-3.0 - PowerShell 删除列标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24195450/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com