OBJECTIVES :-
I'm having trouble with something that should be relatively simple? Searched similar questions here but no cigar. I dont want to have to pass a command to the file as a Ps1 script (common suggestion). I'm hoping I can just right click, run with PowerShell and it works.
SITUATION :-
I have to automate uninstalling of software often. Rather than scour the registry for msiexec strings, I edited some PS code so I can search for what I want, then do whatever I need to do with the info I receive. The below runs fine in PowerShell ISE, but as a PS1 script (right click, run with PS) it outputs nothing on the screen.
CODE :-
$Prog = Read-Host -Prompt 'Input your Prog name'
Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where-Object {$_.DisplayName -match "$Prog"} | Select-Object -Property DisplayName, UninstallString
pause
Lets say at the prompt I search for 7-Zip in ISE I get this...
Input your Prog name: 7-zip
DisplayName UninstallString
----------- ---------------
7-Zip 19.00 (x64) C:\Program Files\7-Zip\Uninstall.exe
Running as a script, I get nothing output into the console?
Input your Prog name: 7-zip
Press Enter to continue...:
QUESTION :- What do I need to do to make the script behave like it does in the ISE console?
Many thanks for any assistance
P.S (<see what I did there, I'm new to the PowerShell game, thanks>)