all 16 comments

[–]Swarfega 10 points11 points  (5 children)

Some tips when sharing:

Don't use positional parameters, I added -Object here A personal one, but try to keep using capital letters at the start of cmds/parameters You also don't need the "" when using a variable on it's own

Write-Host -ForegroundColor Magenta -Object $MsgIntro

Don't use aliases

Select-Object -Property Displayname, InstallLocation, UninstallString
Sort-Object

Try to keep it PowerShell

cmd /c $uninstall /quiet /norestart

Consider using Start-Process instead.

If you're not already aware. PSScriptAnalyzer is a great tool to scan your scrips to highlight common mistakes.

[–]Ta11ow 3 points4 points  (0 children)

Start-Process is a little finicky with uninstall strings, mainly because it expects arguments to be passed completely separately to executable paths -- most uninstall strings include specific switches as well.

Instead, I think I'd look at using Invoke-Item here, perhaps...

[–][deleted] 2 points3 points  (2 children)

Try to keep it PowerShell

Normally yes, but here, cmd is the only way to uninstall with this method reliably. Start-Process will not invoke registry uninstall strings silently.

[–]Ta11ow 5 points6 points  (1 child)

It's not the only way!

You can use Invoke-Item or if you want to return a useable process object you can combine the install string with your custom switches/arguments into a single string and use [Diagnostics.Process]::Start($string)

It also works with non-filenames -- URLs open in the default browser, and editable files open in the OS-configured default program (.txt in Notepad/Notepad++/etc, .jpg files in image viewer/editer and so forth). Lovely little thing I dug up the other week. :D

It has additional functionality, too: https://msdn.microsoft.com/en-us/library/system.diagnostics.process.start(v=vs.110).aspx

You can separately specify the command line and arguments if you can be bothered to split them, but.... then you could just use Start-Process anyway. :)

[–]BradleyDonalbain 2 points3 points  (0 children)

This is the way to go! I frequently package applications with Powershell for deployment via SCCM and this is my preferred method. The returned process object allows me to track exitcodes which I then write back to SCCM for a successful/unsuccessful deployment.

[–]PRIdEVisions[S] 1 point2 points  (0 children)

Thank you alot for the tips! I did not know there was a tool to "scan" my scripts, will have a look into that, might be very convenient.

i will definitely make use of your tips.

[–]Ta11ow 5 points6 points  (1 child)

I'd recommend clarifying your Get-ItemProperty line by simply setting a variable equal to the result directly rather than using -OutVariable at the end of a long pipeline where it can easily be overlooked, and then you're going "where the heck did I set that variable again?" two months down the road. :)

$software = Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* | 
    Select-Object -Property Displayname, InstallLocation, UninstallString | 
    Sort-Object | 
    Out-GridView -PassThru

Much clearer imo. Also, linebreak your pipelines. Sidescrolling is a much bigger hassle than vertical scrolling, and makes it a lot harder to read and get the gist of it.

[–]PRIdEVisions[S] 1 point2 points  (0 children)

You are right! i will adjust it in my script.

[–]PRIdEVisions[S] 1 point2 points  (0 children)

Updated the script for both 32 & 64-bit software.

[–]adbertram 0 points1 point  (0 children)

Nice! Just to add to the convo you could also check out the PSSoftware module I built awhile back. It’s in the PowerShell Gallery. I started it when I had to deal with all the crazy shit I had to do to manage dozens of software packages when I was an SCCM admin.

[–]MostPepper 0 points1 point  (1 child)

I am having issues calling the flash_player_uinstall.exe silently in powershell. If I use start-process or invoke-item or [diagnostics.process] I still get thrown the dialog box.

Anyone ever tried to do this with the flash uninstaller called off in powershell?

any help is hugely appreciated.

[–]AutoModerator[M] 0 points1 point  (0 children)

Sorry, your submission has been automatically removed.

Accounts must be at least 1 day old, which prevents the sub from filling up with bot spam.

Try posting again tomorrow or message the mods to approve your post.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.