Why is WMIC giving me Invalid query when trying to uninstall? - powershell

I'm trying to uninstall regular programs via PowerShell, and everything I've tried to put in the name="program name" section, appears to fail.
I've followed this guide here on how to do it.
I've tried removing Google Chrome as my test example. It's not actually want I want to remove, just a test target that I can easily and quickly reinstall.
I did first test on another machine which had Google Chrome, but didn't show up in this list. It also had this error. But now I tested on my main machine, where Google Chrome does show up in the list.
PS C:\WINDOWS\system32> wmic product get name Name
Microsoft Visual C++ 2010 x64 Redistributable - 10.0.40219
Microsoft Visual C++ 2010 x86 Redistributable - 10.0.40219
Microsoft Visual Studio 2010 Tools for Office Runtime (x64)
Google Chrome
Google Update Helper
Microsoft SQL Server 2008 Native Client
PS C:\WINDOWS\system32> wmic product where name="Google Chrome" call uninstall
ERROR:
Description = Invalid query
Some irrelevant product get name entries have been removed to keep the list short.
I expect WMIC to uninstall the program, but instead I get the error found above.

The WMIC command requires the filter within quotes: wmic product where "name='Google Chrome'"
Powershell also exposes the Get-WMIObject cmdlet (alias gwmi) that has cleaner syntax:
$chrome = gwmi win32_product -filter "name='Google Chrome'"
$chrome.Uninstall

You can try the package commands too.
get-package *chrome* | uninstall-package -whatif

Try this
wmic product where "name like 'Google Chrome'" call uninstall
use '' on program name and "" on name

Related

See the version of the services that are installed

I want to see the version numbers of the services that are installed on my PC via PowerShell. But it only shows me Status, Name, DisplayName. How can I see the version numbers of services using PowerShell. Below you can see the code that I'm using. (I want to see the versions of the services that has the word "Arda" in it, because of that I use -Name "Arda*" parameter.
Get-Service -Name 'Arda*'

Uninstall all software starting with a specific string

Following this issue, I want to uninstall all the National Instrument software. From here first enter the wmic in CMD. Then using the command product get name I get a bunch of software all starting with NI:
NI Logos 19.0
NI Trace Engine
NI-MXDF 19.0.0f0 for 64 Bit Windows
WIF Core Dependencies Windows 19.0.0
NI-VISA USB Passport 19.0.0
NI-VISA SysAPI x64 support 19.0.0
NI Controller Driver 19.0 64-bit
NI ActiveX Container (64-bit)
Math Kernel Libraries
NI MXS 19.0.0
NI LabWindows/CVI 2019 Network Variable Library
NI-VISA GPIB Passport 19.0.0
NI LabWindows/CVI 2017 Low-Level Driver (Original)
NI-RPC 17.0.0f0 for Phar Lap ETS
NI LabWindows/CVI 2017 .NET Library (64-bit)
...
I can uninstall them individually by for example:
product where name="NI Logos 19.0" call uninstall
and then I have to select y/Y. Given there are a lot of these software which I have to uninstall, I was wondering how I can automatize this process. The steps should be something like this:
find all the lines in product get name starting with NI and make a list out of it
a for loop on the above list running product where name=list[i] call uninstall with the default y/Y
I would appreciate if you could help me with this issue. Thanks for your support in advance.
P.S. Powershell solutions are also ok. In fact, any other solution to uninstall all of these using any other way is OK for me.
You should be able to use the Like operator with wmic.
From cmd
WMIC Product Where "Name Like 'NI%'" Call Uninstall /NoInteractive
From a batch-file
WMIC Product Where "Name Like 'NI%%'" Call Uninstall /NoInteractive
No command line options are documented as available to to the Uninstall call, so using /NoInteractive is offered here more in hope than as a definitive solution to your stated prompt.
If the applications were installed from an MSI you could use the following PowerShell code. If some other installer was used, you could add the silent uninstall parameters to the $uninstallString in the loop:
$productNames = #("^NI")
$uninstallKeys = #('HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',
'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall')
foreach ($key in (Get-ChildItem $uninstallKeys))
{
foreach ($productName in $productNames)
{
$name = $key.GetValue("DisplayName")
if ($name -match $productName)
{
$uninstallString = $key.GetValue("UninstallString")
if ($uninstallString -match "^msiexec(\.| )")
{
$uninstallString = ($uninstallString -replace "/I{","/X{" -replace "/X{", '/X "{' -replace "}",'}"') + " /qn /norestart"
}
Write-Host "Removing '$name' using '$uninstallString'..."
& cmd.exe /C $uninstallString
}
}
}

How to activate Windows 2012 R2 Terminal License with command line

I have Installed Remote Desktop Session Host and Remote Desktop Licensing services on Windows 2012 R2 Server which is working in WORKGROUP.
I have Enterprise Agreement Number for "Per user Cal Licensing". Normally I can make this activation using Remote Desktop Licensing Manager. But, I want to make this activation via command line such as powershell or cmd..
I need to fill some fields such as company name, email, name surname, Enterprise Agreement Number etc..
Is there any way to make this or it is impossible via command line ??
I found this command ;
gwmi -namespace "Root/CIMV2/TerminalServices" Win32_TerminalServiceSetting
But, I could not found usage scenario for my case.
First of all, you need to import the module
Import-Module RemoteDesktopServices
Then you can use:
Set-RDLicenseConfiguration -LicenseServer license_server_name -Mode PerUser -ConnectionBroker connection_broker_name

PowerShell: Firefox version check using Powershell

Trying to uninstall firefox using a powershell bat script. But i need to know which Firefox version is currently running and what is the folder name under program files/! I go lots of long script like: https://p0w3rsh3ll.wordpress.com/2012/02/19/get-firefoxinfo/
but i just want something simple which just return the current firefox version.
Firefox specifically contains a command-line option to get the version, as well as instructions on how to use it on Windows. This one-liner will get your current Firefox version (presuming you're in the right folder or your Firefox is in the system path):
$ffversion = [string](.\firefox.exe -v| Write-Output)
The | Write-Output bit is crucial, for now, due to a documented bug. The result is then converted to a string (also necessary) and saved as a variable here.
Assuming Firefox is installed in typical location:
wmic datafile where name='c:\\program files (x86)\\Mozilla Firefox\\Firefox.exe' get version
Just try below command in PowerShell -
PS> gp HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |Select DisplayName, DisplayVersion, Publisher, InstallDate, HelpLink, UninstallString |ogv
This will display a popup with all the version details of installed software. In there Add Criteria and Set the DisplayName to Firefox.
You will get the version.
On x64 machines, if you want to do it with gp, you need
PS> gp HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select DisplayName, DisplayVersion, Publisher, InstallDate, HelpLink, UninstallString |ogv
Thanks!
$firefox = (Get-Item (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe').'(Default)').VersionInfo

A map network drive not showed with Powershell, but is with VBS?

I have made a function with powershell that list all the available drive letters for mapping a new drive. This is working just fine at work(On a domain, Win 7, 64 bit).
But here at home, at my private computer(not on a domain, Win 8.1, 64 bit) I can't get Powershell to see my Map Drive R:.
It's there, in explore and when I use VBS:
Net use r:
Local name R:
Remote name \\10.10.10.10\Folder
Resource type Disk
The command completed successfully.
In powershell I use the following code:
Get-PSDrive | Where-Object name -EQ 'r'
And Im not getting any result back. If I look in WMI, I'm still not getting anything. Here I use the following code:
Get-CimInstance win32_LogicalDisk | Where-Object DeviceID -EQ 'r:'
I found this link, Getting a free drive letter, and even with this code, it's still select my R:\ as an available drive letter.
Can some point me a the right direction, please :-) ?
Bonus info:
At work all drives are mappet to windows computers.
At home my r:\ is mappet to a linux, nas server(Qnap TS 410).
Get-SMBshare
Don't show the R: drive ether.
Microsoft has issued a knowledge base article (KB3035277) about the issue you reported:
Mapped drives are not available from an elevated prompt when UAC is configured to "Prompt for credentials" in Windows
In the article Microsoft confirms that this is a problem in a number of listed Microsoft products (including Windows 8.1) and they offer two different work arounds.