Search code examples
.netpowershellwritetofile

Write to file with PowerShell not working


I'm trying to write to a file the result of:

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

And it doesn't work at all. I've tried using:

$installedPrograms >> "installedProgram.txt"

and

$installedPrograms | Out-File "installedPrograms.txt"

and

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

None of the above worked...


Solution

  • Probably better in a csv

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