Why is my PowerShell script creating an empty file for installed programs?

0
29
Asked By Curious_Coder42 On

Hi everyone, I'm new here and really enjoying the community! I'm trying to generate a text file that lists all the programs installed on my computer using PowerShell. I want the output to include the fields: DisplayName, DisplayVersion, Publisher, Size, and InstallDate. However, when I run my script:

`Get-ItemProperty HKLM:SoftwareMicrosoftWindowsCurrentVersionUninstall*, HKLM:SoftwareWow6432NodeMicrosoftWindowsCurrentVersionUninstall*, HKCU:SoftwareMicrosoftWindowsCurrentVersionUninstall* |Select-Object DisplayName, DisplayVersion, Publisher, Size, InstallDate | Format-Table -AutoSize > C:UsersUSERNAMEDesktopsoftware.txt`

I am left with an empty file on my Desktop. I've double-checked that I changed 'USERNAME' to my actual username, but still nothing seems to be recorded. What could be causing this? Any advice would be greatly appreciated!

5 Answers

Answered By CodeNinja99 On

It seems like adjusting your output method might help. Instead of using `Format-Table`, which is more suited for displaying data on the screen, consider using `Export-Csv` for properly structured data in CSV format. If you prefer a simple text, using `Out-String` might be a better option.

Answered By TechieTommy On

It looks like you're trying to extract values from the uninstall keys, but those keys might not actually have the info you're looking for. Instead, you should get the values from their subkeys. Try adding a wildcard like `uninstall/*` or using `Get-ChildItem` to handle the uninstall keys and see if that gives you a better result!

Answered By EngagedExplorer On

Good catch! Avoid using `Format-Table` since it’s intended for display on the screen. When you're writing to a file, `Out-File` is much more effective for saving your output. Just a little tweak and it should work fine!

Answered By PowerShellPro On

Welcome to the forum! I recommend checking out this archived blog post on the Scripting Blog. It provides some useful information about finding installed software with PowerShell, and it explains why `Win32_Product` can be problematic. Plus, here's another link that showcases a quick method to get installed applications [Get installed applications](https://www.reddit.com/r/PowerShell/comments/t9d1u9/get_installed_applications/). Take care!

Answered By ScriptWizard On

I noticed you're working with specific registry paths. Make sure those paths exist by testing them first. If they do, consider using `Get-ChildItem` to gather the installed software details, and remember not to use `Format-Table` for file output—it’s not designed for that. Using `Out-File` would be a better fit!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.