Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable a Windows feature via Powershell

Tags:

powershell

I need to enable two Windows Features using Powershell. But I don't know their names or how to find them.

Windows Features

So far I have managed to install the IIS and stop the Default Application Pool using a script found here.

function InstallFeature($name) {     cmd /c "ocsetup $name /passive" } InstallFeature IIS-WebServerRole     InstallFeature IIS-WebServer         InstallFeature IIS-CommonHttpFeatures             InstallFeature IIS-DefaultDocument             InstallFeature IIS-DirectoryBrowsing             InstallFeature IIS-HttpErrors             InstallFeature IIS-HttpRedirect             InstallFeature IIS-StaticContent         InstallFeature IIS-HealthAndDiagnostics             InstallFeature IIS-CustomLogging             InstallFeature IIS-HttpLogging             InstallFeature IIS-HttpTracing             InstallFeature IIS-LoggingLibraries         InstallFeature IIS-Security             InstallFeature IIS-RequestFiltering             InstallFeature IIS-WindowsAuthentication         InstallFeature IIS-ApplicationDevelopment             InstallFeature IIS-NetFxExtensibility             InstallFeature IIS-ISAPIExtensions             InstallFeature IIS-ISAPIFilter             InstallFeature IIS-ASPNET     InstallFeature IIS-WebServerManagementTools          InstallFeature IIS-ManagementConsole          InstallFeature IIS-ManagementScriptingTools  import-module WebAdministration  Stop-WebAppPool DefaultAppPool 

Solution

To search:

Get-WindowsFeature *ASP* Get-WindowsFeature *activation* 

To install:

Add-WindowsFeature NET-Framework-45-ASPNET Add-WindowsFeature NET-HTTP-Activation 
like image 641
Kasper Hansen Avatar asked Jan 09 '13 13:01

Kasper Hansen


People also ask

How do I activate Windows using PowerShell?

1. Type Start PowerShell in the Command Prompt window to start Windows PowerShell. 2. Type Install-WindowsFeature WAS and press Enter to install the Windows Process Activation Service.


2 Answers

For newer Windows client OS (Windows 10/8.1/8) you cannot use Install-WindowsFeature as that is only for managing features on servers. Trying to use it will cause an error message:

Get-WindowsFeature : The target of the specified cmdlet cannot be a Windows client-based operating system.

There is a DISM Powershell module that you can use to find and install optional features:

gcm -module DISM #List available commands Get-WindowsOptionalFeature -online | ft #List all features and status Enable-WindowsOptionalFeature -online -FeatureName NetFx3 -Source e:\Sources\sxs 

In the last command -Source e:\Sources\sxs is only required if the feature needs to reference the installation media for source files (usually to fix Error: 0x800f081f The source files could not be found). The .NET Framework version 3.5 seems to be the only one that requires that for the client OS, but there are many others on the Server OS that require referencing the installation media for sources.

like image 173
Greg Bray Avatar answered Sep 20 '22 09:09

Greg Bray


if you are in windows 2008R2 there is a module for this :

Import-Module servermanager

this module exports 3 cmdlets : Get-WindowsFeature, Add-WindowsFeature and remove-WindowsFeature

so you can make someting like get-windowsfeature *frame* to list the .net features and install it via command like Add-WindowsFeature Net-Framework

like image 41
Loïc MICHEL Avatar answered Sep 23 '22 09:09

Loïc MICHEL