powershell脚本:删除csv输出文件周围的“”引号

时间:2014-06-23 21:50:42

标签: powershell

我正在尝试删除我的csv输出文件中的引号,但代码无效。我遵循了提供的指导原则,但仍然没有删除引号。

$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 -Encoding ascii | % {$_ -replace '"', ""} | Out-File $OutFile -Force -Encoding ascii

1 个答案:

答案 0 :(得分:0)

如果它看到一个字符串,

Export-Csv将把引号放回到文件中。最好的办法是使用Out-File来实际写入CSV。

这应该替换你的代码:

@{n='Object Path';e={$fldr}} | ConvertTo-Csv -NoTypeInformation | % {$_ -replace '"', ""} | Out-File $OutFile -Force -Encoding ascii -Append