Powershell Techniques
PowerShell Scripts Resources
Book: PowerShell Cookbook PowerShell Commands @ SS64.com
Powershell, VB Script, SQL and JavaScript PowerShell Code Repository chriskenis/POSH · GitHub
How to obtain GUID of installed application?
Finding all installed applications Use PowerShell to Quickly Find Installed Software - Hey, Scripting Guy! Blog - Site Home - TechNet Blogs
- WMI object win32_product: very nice, but extremely slow, and floods Events in Windows
- WMI Win32reg_AddRemovePrograms: not available everywhere
- Raw registry search (but all the subtrees). Still the best way to do it. Fast and compatible.
Best script so far (3rd technique): Get-InstalledSoftware
:: Command Line
for /f “tokens=7 delims=" %g in (‘reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall ^| %SystemRoot%\System32\find.exe “{”’) ^
do for /f “tokens=3,*” %p in (‘reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall%g ^| %SystemRoot%\System32\find.exe /i “DisplayName”’) do echo %p,%g
:: In a batch file for /f “tokens=7 delims=" %%a in (‘reg query hklm\software\microsoft\windows\currentversion\uninstall ^| FIND “{”’) do for /f “tokens=2,*” %%c in (‘reg query hklm\software\microsoft\windows\currentversion\uninstall%%a ^| find /i “DisplayName”’) do echo %%d,%%a
:: Command line output all to a file. for /f “tokens=7 delims=" %a in (‘reg query hklm\software\microsoft\windows\currentversion\uninstall ^| FIND “{”’) do for /f “tokens=2,*” %c in (‘reg query hklm\software\microsoft\windows\currentversion\uninstall%a ^| find /i “DisplayName”’) do echo %d,%a»GUIDSoftware.txt
for /f “tokens=3,*” %p in (‘reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall{F842F8B0-6942-4930-821F-543E976B2C66} ^| %SystemRoot%\System32\find.exe /i “DisplayName”’) do echo %p, {F842F8B0-6942-4930-821F-543E976B2C66}
This can be probably done in simple DOS, but I didn’t manage to do it. I was close, tough. Registry keys of interest are:
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
Similar technique using Powershell Powershell Uninstall Software Function | Tech Notes
Much better way is with Powershell. To get the whole list:
@powershell "Get-WmiObject win32_product | Format-Table name, version, ident*"
or using aliases of cmdlets:
@powershell "gwmi win32_product | ft name, version, ident*"
Usualy, I’m interested in only one package, and the syntax for that is:
@powershell "gwmi win32_product -filter \"Name LIKE '%vagrant%'\""
Uninstall Chrome, for example:
Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -eq "Chrome"} | foreach-object -process {$_.Uninstall()}
Source: How can I uninstall an application using PowerShell? - Stack Overflow Use PowerShell to Find and Uninstall Software Uninstall program from powershell in windows 7
??? This method doesn’t delete items from the start menu – which is a job for another time
New Delhi PowerShell User Group.: Uninstall Software using PowerShell
Win32reg_AddRemovePrograms is a much lighter and effective way to do this PowerShell Code Repository - List AddRemovePrograms
@powershell “gp HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall* |Select DisplayName, DisplayVersion, Publisher, InstallDate, UninstallString "
Powershell: Script to query softwares installed on remote computer
All the registry locations: Blog: HOW TO: Uninstall Program by Name Only | ITNinja
List uninstall strings using powershell | Jesper Lönnqvist’s Blog PowerShell Script Uninstall-Toolbars.ps1
Retrieving installed applications - ITPilgrims
At the end, the Registry solution is the fastest and lists all the software.
Powershell: Script to query softwares installed on remote computer Powershell: Uninstall software on remote computer
Modules .psm1 - loading / reloading
Normally, reloading module would be executed in two commands:
Remove-Module MyModule
Import-Module MyModule
We can shorter that with aliases in one line:
rmo MyModule; ipmo .\MyModule.psm1
But simply the best version is, that does the same thing:
ipmo .\QueryAppInstalled.psm1 -force
And, to skip security warnings, don’t forget to start PowerShell with bypass execution policy:
powershell -executionpolicy bypass
PowerShell command aliases
PowerShell 2.0 commands | SS64.com
- Get-ChildItem = dir / ls / gci
- Get-ItemProperty = gp
List startup items?
Get-Wmiobject Win32_StartupCommand
Talking script?
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://raw.github.com/chriskenis/POSH/master/Misc/MISC_Greeting.ps1'))"