Different ways for installing Windows features on the command line – Peter Hahndorf
Posted by jpluimers on 2023/06/02
If course you can configure Windows Optional Features using the GUI as for instance explained at [Wayback/Archive] How to manage Windows 10’s many ‘optional features | Windows Central.
However, I prefer command-line management.
About the only post doing the comparison of command-line mangement options I could find about is [Wayback/Archive] Different ways for installing Windows features on the command line – Peter Hahndorf and hopefully will be further updated in the future. It is dated 2015, but has been updated until at least Windows Server Nano.
I added one, and then rewrote the tool-set availability table in the post into this:
winget*-WindowsCapability*-WindowsOptionalFeature*-WindowsFeaturedism.exepkgmgr.exe
| Vista+2008 | Win7 | 2008 R2 | Win8.* | 2012 R* | Win10 | 2016 | Nano | Source | |
*-WindowsOptionalFeature |
* | * | * | * | * | Dism module |
|||
*-WindowsCapability |
* | * | ? | Dism module |
|||||
*-WindowsFeature |
* | * | ServerManager module |
||||||
winget.exe |
* | * | |||||||
dism.exe |
* | * | * | * | * | * | * | %SystemRoot%\System32 |
|
pkgmgr.exe |
* | * | * | * | * | * | * | * | %SystemRoot%\System32 |
On modules: [Wayback/Archive] PowerShell 7 module compatibility – PowerShell | Microsoft Docs / [Wayback/Archive] PowerShell-Docs/module-compatibility.md at staging · MicrosoftDocs/PowerShell-Docs
MODULE LIST Module name Status Supported OS DismNatively Compatible Windows Server 1903+
Windows 10 1903+ServerManagerNatively Compatible Windows Server 1809+
Windows 10 1809+ withRsat.ServerManager.Tools
See notes below
ServerManagermoduleThis module has some minor compatibility issues with formatted output in PowerShell 7. For example, theGet-WindowsFeaturecmdlet returns the proper object with all properties, but the default display formatting makes some properties appear to be empty. The actual values are available in the object properties usingSelect-Objector by direct member access.
Note that not all tool can perform all kinds of installations, for instance:
OpenSSHcan only be installed usingAdd-WindowsCapability, see my blog post Installing Windows OpenSSH from the command-line on Windows 10 and 11
Some more details on the various tool sets are below. I included [Wayback/Archive] SS64 Command line reference reference next to [Wayback/Archive] Developer tools, technical documentation and coding examples | Microsoft Docs as SS64 documents more commands and better “See also” links.
*-WindowsCapability
Part of the PowerShell [Wayback/Archive] DISM Module | Microsoft Docs available as of Windows 10 1903+ and Windows Server 2016 1903+.
Add-WindowsCapabilityGet-WindowsCapabilityRemove-WindowsCapability
*-WindowsOptionalFeature
Part of the PowerShell [Wayback/Archive] DISM Module | Microsoft Docs available as of Windows 8 and Windows Server 2012.
Disable-WindowsOptionalFeatureEnable-WindowsOptionalFeatureGet-WindowsOptionalFeature
This is also documented in [Wayback/Archive] Add or hide optional apps and features on Windows devices – Windows Application Management | Microsoft Docs
*-WindowsFeature
Part of the PowerShell [Wayback/Archive] ServerManager Module | Microsoft Docs available as of Windows Server 2012 (available as of Windows 10 1809+ only if Rsat.ServerManager.Tools is installed).
Get-WindowsFeatureAdd-WindowsFeature(cmdlet on Windows Server 2008 R2; as of Windows Server 2012 it is alias for Get-WindowsFeature)Install-WindowsFeatureRemove-WindowsFeature-
Uninstall-WindowsFeature
winget.exe
Available as of Windows 10 2004+
- [Wayback/Archive] Winget – Windows CMD – SS64.com
- My blog post Installing the Microsoft Store version of Windows Terminal via the
wingetcommand-line - It cannot provision for all users, only for the current user, so it is not possible to run as SYSTEM user:
Just like in the UI, on the CLI you also often need to accept source agreement terms (once per source) or package agreement terms (once per package). Via [Wayback/Archive] winget accept terms commandline switch – Google Search I found:
- [Wayback/Archive]
installCommand | Microsoft Docs
--accept-package-agreementsUsed to accept the license agreement, and avoid the prompt. --accept-source-agreementsUsed to accept the source license agreement, and avoid the prompt. - [Wayback/Archive]
upgradeCommand | Microsoft Docs: options
--accept-package-agreementsUsed to accept the license agreement, and avoid the prompt. --accept-source-agreementsUsed to accept the source license agreement, and avoid the prompt. - [Wayback/Archive] winget aggresively now prompts to accept terms unnecessarily · Discussion #1536 · microsoft/winget-cli
@nascentt, there is an--accept-package-agreementsparameter for package level agreements.There is an--accept-source-agreementsparameter for source level agreements.These are listed in help for the commandwinget upgrade -?Link to Microsoft Docs for upgrade command: https://docs.microsoft.com/windows/package-manager/winget/upgradeOne you have accepted a source agreement, you shouldn’t be prompted again unless the source agreement changes. - [Wayback/A] Accept terms programmatically · Discussion #1758 · microsoft/winget-cli
winget upgrade --accept-source-agreementsworks….
At the time of writing, there was no way to install Microsoft Store applications through winget without having a Microsoft Store account. When trying you get the error “no store account found“. Direct download from the store does not require such an account. See these links:
- [Wayback/Archive] powershell – Bypass option for winget for “no store account found” – Stack Overflow (thanks [Wayback/Archive] Alymsin, [Wayback/Archive] marsze and [Wayback/Archive] Suirtimed):
Q
I’m trying to install sysinternals for our computers remotely, but when attempting to install with
winget install sysinternals --accept-source-agreements --accept-package-agreementsI’m getting “Verifying/Requesting package acquisition failed: no store account found”I can go into the Microsoft Store directly to install it and it asks me if I want to sign in or use “No Thanks” to install, which then works, but this isn’t what I’m intending to do, I don’t want to go to each machine to do this. I could probably try the other method of installing through Powershell from here serverfault.com/questions/1018220/how-do-i-install-an-app-from-windows-store-using-powershell, but this again, is not what I’m intended.
A
This isn’t supported yet (as of January 2022). There is an open issue at GitHub: github.com/microsoft/winget-cli/issues/158
- [Wayback/Archive] winget-cli/MSStoreInstallerHandler.cpp at 1a6a60fddd95480d4f1d9bb1c9abbab84f3cc4b4 · microsoft/winget-cli – Line 86
87elseif (enr.Status() == GetEntitlementStatus::NoStoreAccount)88{89context.Reporter.Info() << Resource::String::MSStoreInstallGetEntitlementNoStoreAccount << std::endl;90AICLI_LOG(CLI, Error, << "Get entitlement failed. No Store account.");91} - [Wayback/Archive] Allow `
winget` to install MS Store packages without account just like the MS Store · Issue #1585 · microsoft/winget-cli - This workaround no longer works:[Wayback/Archive] How do I install an app from Windows Store using Powershell – Server Fault
as of: 06/25/2021 this is broken.
Download-AppxPackageno longer works
- [Wayback/Archive] winget-cli/MSStoreInstallerHandler.cpp at 1a6a60fddd95480d4f1d9bb1c9abbab84f3cc4b4 · microsoft/winget-cli – Line 86
- Via: [Wayback/Archive] winget cli add “no store account found” – Google Search does not have many hits, but at least they are working on it and made me find this:
- [Wayback/Archive] Can’t get OneNote from Windows Store ugh 😒 Seriously what is this crap : windows solved with
Try resetting the MS store (Settings> System> Apps & features> Click Store> Advanced options> Reset.) and also clear its Cache, by typing into run: WSReset.exe
- [Wayback/Archive] Can’t get OneNote from Windows Store ugh 😒 Seriously what is this crap : windows solved with
Also at the time of writing there was no official PowerShell PackageManagement Module support for winget, but there is:
- a request for such a provider: [Wayback/Archive] Add Native PowerShell Support · Issue #221 · microsoft/
winget-cli - an open source provider for it:
More on the PowerShell PackageManagement structure at [Wayback/Archive] windows – PowerShell Package Management – Repository vs Provider vs Source – Stack Overflow
And most API calls in [Wayback/Archive] PackageManagement Module – PowerShell | Microsoft Docs (few are in [Wayback/Archive] PowerShell commands – PowerShell – SS64.com):
Find-PackageFind-PackageProviderGet-PackageGet-PackageProviderGet-PackageSourceImport-PackageProviderInstall-PackageInstall-PackageProviderRegister-PackageSourceSave-PackageSet-PackageSourceUninstall-PackageUnregister-PackageSource
dism.exe
Available as of Windows 7 and Windows Server 2008 R2.
- [Wayback/Archive] DISM – Deployment Image Servicing and Management – Windows CMD – SS64.com
- [Wayback/Archive] DISM Overview | Microsoft Docs
- [Wayback/Archive] DISM Module | Microsoft Docs
pkgmgr.exe
Available as of Windows Vista and Windows Server 2008.
Other commands
- [Wayback/Archive]
Disable-ADOptionalFeature– Active Directory – PowerShell – SS64.com - [Wayback/Archive]
Enable-ADOptionalFeature– Active Directory – PowerShell – SS64.com - [Wayback/Archive]
Get-ADOptionalFeature– Active Directory – PowerShell – SS64.com - [Wayback/Archive]
Get-CimAssociatedInstance– PowerShell – SS64.com - [Wayback/Archive]
Get-CimClass– PowerShell – SS64.com - [Wayback/Archive]
Get-CimInstance– PowerShell – SS64.com - [Wayback/Archive]
Invoke-CimMethod– PowerShell – SS64.com - [Wayback/Archive]
New-CimInstance– PowerShell – SS64.com - [Wayback/Archive]
Remove-CimInstance– PowerShell – SS64.com - [Wayback/Archive]
Set-CimInstance– PowerShell – SS64.com
–jeroen







Leave a comment