我有一個powershell腳本運行並獲得服務器的安全權限,並在csv中輸出這些腳本。目前它輸出的信息,但每個文件它讀取它包括頭帳戶,Ace字符串和對象路徑再次:我如何刪除所以它只顯示在文檔的開始?Powershell腳本輸出csv文件重構
帳戶,王牌字符串,對象路徑 NT AUTHORITY \ SYSTEM,允許FullControl,(繼承),C:\用戶\ munjanga \文檔\ Operations Orchestration的\碼頭 BUILTIN \管理員,允許FullControl,(繼承) ,C:\用戶\ munjanga \文檔\ Operations Orchestration的\碼頭 EMEA \ munjanga,允許FullControl,(繼承),C:\用戶\ munjanga \文檔\ Operations Orchestration的\碼頭 帳戶,王牌字符串,對象路徑 NT AUTHORITY \ SYSTEM,允許FullControl,(繼承),C:\ Users \ munjanga \ Documents \ Operations Orchestration \ jre1.6
$OutFile = "C:\Users\munjanga\Documents\AoN Project\Execute\$([Environment]::MachineName).txt"
$Header = "Folder Path,IdentityReference,AccessControlType,IsInherited,InheritanceFlags,PropagationFlags"
Del $OutFile
Add-Content -Value $Header -Path $OutFile
$RootPath = "C:\Users\munjanga\Documents\Operations Orchestration"
$Folders = dir $RootPath -recurse | where {$_.psiscontainer -eq $true}
$isInherited = @{
$true = 'Inherited'
$false = 'Not Inherited'
}
$inheritance = @{
0 = 'files only'
1 = 'this folder and subfolders'
2 = 'this folder and files'
3 = 'subfolders and files'
}
$fldr = $Folder.FullName
$Folders | % {
$fldr = $_.FullName
Get-Acl $fldr | select -Expand Access |
select @{n='Account';e={$_.IdentityReference}},
@{n='Ace String';e={"{0} {1}, {2} ({3})" -f $_.AccessControlType,
$_.FileSystemRights, $inheritance[$_.InheritanceFlags],
$isInherited[$_.IsInherited]}},
@{n='Object Path';e={$fldr}} | ConvertTo-Csv -NoTypeInformation | % {$_ -replace '"', ""} | Out-File $OutFile -Force -Encoding ascii -Append}
您目前在兩個不同的地方獲得不同的標題。 'Add-Content'這一行是在文件頂部添加'$ Header'值,然後'ConvertTo-Csv'從'Get-Acl'和其後添加額外的頭文件。你想要兩個嗎?或者只是頂部的標題? –
我只想讓文件頂部的標題保留下來,怎麼做?它只是簡單地刪除convertTocsv? – user3738022