[英]I cant format the output of this command correctly
這是我正在執行的命令:
Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\*" | Where-Object {$_."(default)" -ne $null} | Select-Object @{ expression={$_.PSChildName}; label='Program'} ,@{ expression={$q + $_."(default)" +$q}; label='CommandLine'}
這是 output 的片段:
Program CommandLine
------- -----------
7zFM.exe C:\Program Files\7-Zip\7zFM.exe
AcroRd32.exe C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe
Adobe Audition CC.exe "C:\Program Files\Adobe\Adobe Audition CC 2019\Adobe Audition CC.exe"
Adobe Media Encoder.exe "C:\Program Files\Adobe\Adobe Media Encoder CC 2019\Adobe Media Encoder.exe"
Adobe Premiere Pro.exe "C:\Program Files\Adobe\Adobe Premiere Pro CC 2019\Adobe Premiere Pro.exe"
AfterFX.exe C:\Program Files\Adobe\Adobe After Effects CC 2019\Support Files\AfterFX.exe
BJMYDGN.EXE C:\Program Files\Canon\MyPrinter\BJMyDgn.exe
BJMYPRT.EXE C:\Program Files\Canon\MyPrinter\BJMyPrt.exe
我是文本格式的新手,我正在嘗試在 csv 文件中創建它,其中包含 2 列、程序和可執行文件並刪除所有引號“”。 $q + 刪除引號,但是如果一個項目有 2 組引號,一組仍然如上(對不起,我應該澄清..
我想我在兜圈子,只是在尋求幫助。
我通過管道計算出 csv 格式:
| Export-Csv -Path .\programs.csv -Encoding ascii -NoTypeInformation
.NET 中的字符串 object 有一個Trim()方法,該方法通常從字符串的開頭和結尾去除空格,但也可以采用字符數組來去除。
因此,將 CommandLine 的表達式修改為以下內容就足夠了:
$_.'(default)'.Trim('"')
PS我不確定你在命令行表達式中的$q
變量是什么。 但我認為你不需要它。
像這樣?
Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\*" | Where "(default)" -ne $null |
Select @{ E={$_.PSChildName}; N='Program'} ,@{ E={$_."(default)".Trim('"')}; N='CommandLine'} |
export-csv .\programs.csv -Encoding ascii -NoType
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.