Get-Package | Uninstall Package doesn't work, no error - windows

I try to list all applications, choose one of them and uninstall it, kind of like in control panel.
$package = get-package | Out-GridView -PassThru
Get-Package -Name $package.Name | Uninstall-Package
when I execute this and choose Google Chrome, it doesn't do much.
this is probably a dumb question, not new to PowerShell but not veteran either

The Uninstall-Package cmdlet can't delete entries where "ProviderName" is "Programs"
Example:
get-package *chrome*
Name Version Source ProviderName
---- ------- ------ ------------
Google Chrome 105.0.5195.127 Programs
In general Programs with "ProviderName" property as "Programs" are ones that are installed via .exe .
If you want to uninstall packages with PackageManagement/PowerShellGet they need to be installed by PackageManagement/PowerShellGet.
Alternative would be to install Chocolatey Package Provider and it should be able to delete it

Related

Package Manager Console prompt is messed up after installing oh-my-posh

I have oh-my-posh and posh-git installed and added to my Powershell profile, which looks like this
Import-Module posh-git
Import-Module oh-my-posh
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\thecyberden.omp.json" | Invoke-Expression
I'm using the CaskaydiaCove NF font in Powershell, which I also set as the font for the Package Manager Console.
My Windows Terminal prompt is correct:
However, the Package Manager Console in Visual Studio is weird, like it's not able to find the correct glyphs:
Is there a way to fix my Package Manager Console prompt so that either it displays correctly like Powershell, or so that it ignores the Powershell profile and just uses its default prompt?
This is because that shell doesn't support ANSI. Have a look at the PowerShell settings in case this is 7, otherwise there's no fix for it.

GPUdate PS Commandlet

I'm having an issue with this script. For some reason, it was working previously and now it is not. It is now returning with:
Invoke-GPUpdate : The term 'Invoke-GPUpdate' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
Write-Host "Refreshing Group Policies on the local machine......."
Invoke-GPUpdate -Computer $computer -RandomDelayInMinutes 0 -force ForegroundColor Cyan
Start-Sleep -s 20
Invoke-GPUpdate is part of the GroupPolicy module. GroupPolicy is not available by default, but is included with RSAT Tools. What likely happened is a major update to Windows occurred and in this case, if RSAT Tools isn't installed as a Windows Feature (it is only available as a "Feature on Demand" beginning with the Windows 10 October 2018 Update, which is build 17763), it will get removed during the update and needs to be re-installed.
This technically happens with the feature as well I believe, as RSAT Tools is still linked to specific versions of Windows, but the upgrade process will re-install the feature if it was already present.
Installing GroupPolicy RSAT Tools as a feature with Windows PowerShell
If you have Windows 1809 or newer, you can install as a feature using the following command:
Get-WindowsCapability -Name 'Rsat.GroupPolicy.*' -Online | Where-Object { $_.State -ne 'Installed' } | Add-WindowsCapability -Online
You can do the same with other RSAT Tools as well (the features are modularized per their functionality). To enumerate all of them:
Get-WindowsCapability -Name RSAT*
Once again, this requires Windows 1809 or newer or the features will be unavailable. You'll have to install it by using the MSU provided by Microsoft for your Windows version.

Uninstall packages (3rd party anti virus) in windows 10 using powershell

I am trying to uninstall packages using the PowerShell command and script. Every time I run the command it runs and does nothing moreover can't find any logs of it. I tried Microsoft documentation https://learn.microsoft.com/en-us/powershell/module/packagemanagement/uninstall-package?view=powershell-7.1 In stack overflow similar problem Powershell: Find installed Antivirus, filtering out Windows Defender to find the installed antivirus. But When I want to uninstall it simply does nothing.
# Get-Package -Provider Programs -IncludeWindowsInstaller
$appToRemove = Get-Package -IncludeWindowsInstaller -Name Avast
Write-Output $appToRemove
Uninstall-Package $appToRemove -Force -AllVersions -Confirm
I have tried several solutions and stuck for 1 week. Can anyone please help me? Thank you.

How to get path to Linux installation from within WSL in Fall Creators Update

Before the recent update WSL root filesystem was always in C:\Users\%username%\AppData\Local\lxss, but now when Linux is installed from the App Store it can be different for each installation. For example for Ubuntu on my machine it is C:\Users\%username%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs
Is there a way to detect this path from within current WSL session?
As noted by other users, nowadays you can install multiple Linux distributions and each distribution have their own filesystem located in a different folder. The location of each filesystem can be obtained from the Windows Registry.
You can run regedit and look for the information. The data is located under
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss
In addition, you can start a PowerShell window and execute the following command to determine information of all the installed Linux distributions.
(Get-ChildItem "HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss" -Recurse)
To obtain the location of the filesystems, you can run
(Get-ChildItem HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | ForEach-Object {Get-ItemProperty $_.PSPath}) | select DistributionName,BasePath
In PowerShell:
> echo ($env:LOCALAPPDATA + '\Packages\' + ($(get-appxpackage).PackageFamilyName|findstr UbuntuonWindows))
C:\Users\Reker\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc
You can run above command in bash.exe on Windows 14393 or above by interop with windows cmd.exe or powershell.exe

Install msi with msiexec in silent mod and specific directory

I have setup.msi file. I need to run the installation from the command line in silent mode. It is also necessary to specify the path where will this installation. I tried to use TARGETDIR and INSTALLDIR parameters, but the installation going is in the default folder:
msiexec.exe /i c:\setup.msi TARGETDIR="c:\result" /qb
Also if you run this command again, the installation will not happen, because msiexec think that the product is already installed. In this case, I need to get the product installation in the specified directory and the version value in the registry has been updated.
How can I install product in a specific directory regardless of whether the product is installed or not.
Basically, your commandline is not wrong. But, which variable is the correct one, is strongly dependent on the msi package itself, it is not a rule, that TARGETDIR works. At least it works for MSI files following best practices. Normally TARGETDIR is correct, and for InstallShield-builds is INSTALLDIR working best.
But if someone has authored the folder directly as ProgramFilesFolder, then this is fixed.
Download Orca or better InstEd or a similar tool and you have to look inside the MSI file.
Your second question:
"How can I install product in a specific directory regardless of whether the product is installed or not?"
This is not directly possible. Windows Installer has rules, and these don't allow multiple installation in different directories without further effort:
Moreover I am not sure why do you want this:
Here is a bit more knowledge for this:
Normally, everyone who wants to install in another directory, first uninstalls the product. That is standard practice. With commandline parameter /x you can uninstall it. Then install with a new path.
Your are correct, if you install a second time with your (same) command line, nothing will happen or change. Instead of an uninstall a repair (correction) is possible. Use the additional parameters REINSTALL=ALL REINSTALLMODE=vemus for this as a good default.
But as said, it is not possible to change installation path with this.
If you really mean this: For having installed multiple "copies" of the same software in different directories, things are a bit tricky with MSI. I recommand professional MSI knowledge for this so maybe you would need paid consult for that. Most people use copy scripts instead of MSI for such things. But when you want to have real multiple setup versions installed, search for MSDN entry "Installing Multiple Instances with Instance Transforms" as a first starting point.
I use powershell to check if it's already installed and install it if it's not already.
x86 MSI:
((Get-ItemProperty HKLM:\\Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\* | Where { $_.DisplayName -like \"*[APPLICATION_NAME]*\" }) -ne $null)
X64 MSI:
((Get-ItemProperty HKLM:\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\* | Where { $_.DisplayName -like \"*[APPLICATION_NAME]*\" }) -ne $null)
You can take the result and store it in a variable if you want such as $ApplicationInstalled and then condition your installation based on the result.
if (-not $ApplicationInstalled)
{
#MSI Install Commmand
}

Resources