0

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>)

1 Answer 1

1

It works in Powershell too, if you run it from Powershell Interactive Prompt or run using powershell -file "FILEPATH" in CMD/PowerShell, the output remains on the screen. But when you run directly with a double-click output doesn't stay persistent on the screen, instead when it reaches EOF then it quits. So, Add Read-Host or cmd /c pause at the end to stop the program at the end, to view output.

Sign up to request clarification or add additional context in comments.

2 Comments

There must be a way I can right click the file, run with powershell and get the results, i know I can CMD to it, but seems so clunky?
No currently there are nothing so but you can add it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.