使用 PowerShell 写入文件不起作用

Write to file with PowerShell not working

我正在尝试将以下结果写入文件:

$installedPrograms = Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate

而且根本不起作用。我试过使用:

$installedPrograms >> "installedProgram.txt"

$installedPrograms | Out-File "installedPrograms.txt"

$stream = [System.IO.StreamWriter] "installedPrograms.txt"
1..10000|%
{
    $stream.WriteLine($installedPrograms)
}
$stream.Close();
以上的

None 有效...

在 csv 中可能更好

$installedPrograms = Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
$installedPrograms | export-csv installedPrograms.csv -notypeinformation