Error while enabling IISNET45 - powershell

I am running powershell scripts to install IIS. Below is my script
Add-WindowsFeature NET-Framework-45-ASPNET
Add-WindowsFeature NET-HTTP-Activation
Add-WindowsFeature Telnet-Client
Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerRole
Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServer
Enable-WindowsOptionalFeature -Online -FeatureName IIS-CommonHttpFeatures
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpErrors
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpRedirect
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ApplicationDevelopment
Enable-WindowsOptionalFeature -Online -FeatureName IIS-NetFxExtensibility45
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HealthAndDiagnostics
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpLogging
Enable-WindowsOptionalFeature -Online -FeatureName IIS-LoggingLibraries
Enable-WindowsOptionalFeature -Online -FeatureName IIS-RequestMonitor
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpTracing
Enable-WindowsOptionalFeature -Online -FeatureName IIS-Security
Enable-WindowsOptionalFeature -Online -FeatureName IIS-RequestFiltering
Enable-WindowsOptionalFeature -Online -FeatureName IIS-Performance
Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerManagementTools
Enable-WindowsOptionalFeature -Online -FeatureName IIS-IIS6ManagementCompatibility
Enable-WindowsOptionalFeature -Online -FeatureName IIS-Metabase
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ManagementConsole
Enable-WindowsOptionalFeature -Online -FeatureName IIS-BasicAuthentication
Enable-WindowsOptionalFeature -Online -FeatureName IIS-WindowsAuthentication
Enable-WindowsOptionalFeature -Online -FeatureName IIS-StaticContent
Enable-WindowsOptionalFeature -Online -FeatureName IIS-DefaultDocument
Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebSockets
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ApplicationInit
Enable-WindowsOptionalFeature -Online -FeatureName IIS-NetFxExtensibility45
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ASPNET45
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ISAPIExtensions
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ISAPIFilter
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpCompressionStatic
Add-WindowsFeature Web-Scripting-Tools
Add-WindowsFeature MSMQ
Add-WindowsFeature msmq-server, msmq-triggers
Add-WindowsFeature Web-Ftp-Server
I get error
Enable-WindowsOptionalFeature : One or several parent features are disabled so current feature can not be enabled.
At C:\SetupScripts\Install-IIS.ps1:34 char:1
+ Enable-WindowsOptionalFeature -Online -FeatureName IIS-ASPNET45
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Enable-WindowsOptionalFeature], COMException
+ FullyQualifiedErrorId : Microsoft.Dism.Commands.EnableWindowsOptionalFeatureCommand
What am i doing wrong here? Sure something is wrong?

Try to add option -All at the end. The All parameter enables all parent features of the specified feature before enabling the specified feature. The parent feature will be enabled with default values
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ASPNET45 -All
Also please refer
https://learn.microsoft.com/en-us/powershell/module/dism/enable-windowsoptionalfeature?view=win10-ps

I just had the same problem, and found that I had to install IIS-ISAPIExtensions and IIS-ISAPIFilter before installing IIS-ASPNET45. In other words:
...
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ISAPIExtensions
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ISAPIFilter
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ASPNET45
...
I don't know of any easy way to find the parent feature of another feature. It would have been nice if it was a property on the objects returned from Get-WindowsOptionalFeature

You will get it done by adding below in your script
Enable-WindowsOptionalFeature -online -FeatureName NetFx4Extended-ASPNET45

I had same issue like this previously. I solved it by simply by running PowerShell as Administrator. Even after running from elevated PowerShell,if it still throw an error then please try this
Install-WindowsFeature -name Web-Server -IncludeManagementTools
Make sure you run this script from an Admin Prompt!
Make sure Powershell Execution Policy is bypassed to run these scripts:
YOU MAY HAVE TO RUN THIS COMMAND PRIOR TO RUNNING THIS SCRIPT
Set-ExecutionPolicy Bypass -Scope Process

Related

How do you install Hyper V on Azure Dev Ops pipeline?

I am trying to install Hyper V for an Azure Dev Ops (ADO) pipeline (using powershell task). When I do a "Get-VM", I am getting the typical powershell error "... not recognized as the name cmdlet" error so it make me believe Hyper V is not installed. When I do a "Get-Module -listavailable" Hyper V is not listed.
I have a build agent with Windows 2019 and Windows 2022 and neither seems to work.
I have tried the following;
DISM /Online /NoRestart /Enable-Feature /All /FeatureName:Microsoft-Hyper-V /LogLevel:4 <-- seems to work but at the end of the task it just says Exit 1
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -NoRestart -All
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Offline -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Online -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Management-Clients -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Management-PowerShell -NoRestart -All
import-module Hyper-V <-- says can't find module
I am stuck on what to do. I need Hyper V as part of my pipeline tests.
Thanks
Darren
I am afraid that Hyper V can't be enabled on Microsoft Hosted Agents. According to the documentation
Microsoft-hosted agents:
Run on Microsoft Azure general purpose virtual machines Standard_DS2_v2
Hyper V can only be enabled on Virtual Machines which supports Nested Virtualization. Check this link for more details:
https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/user-guide/nested-virtualization
Unfortunately, DSv2-series do not support Nested Virtualization
Figured it out somewhat. Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All is sufficient to do it BUT a reboot is needed which is a new issue. Will follow up with that in a separate posting.

Enable Development time IIS support from PowerShell

I like to keep a PowerShell script that installs and configures my development applications (Visual Studio, VSC, Git etc etc) and environment, mainly using chocolatey. This helps if I change machine or we take on a new developer.
Here is part of my existing script. It installs Visual Studio 2019 and required workloads then enables the local IIS Windows Features for local debugging:
choco install -y visualstudio2019professional
choco install -y visualstudio2019-workload-netweb
choco install -y visualstudio2019-workload-data
choco install -y visualstudio2019-workload-manageddesktop
choco install -y netfx-4.5.2-devpack
Enable-WindowsOptionalFeature -Online -All -FeatureName IIS-WebServerRole
Enable-WindowsOptionalFeature -Online -All -FeatureName IIS-BasicAuthentication
Enable-WindowsOptionalFeature -Online -All -FeatureName IIS-WindowsAuthentication
Enable-WindowsOptionalFeature -Online -All -FeatureName IIS-ASP
Enable-WindowsOptionalFeature -Online -All -FeatureName IIS-ASPNET45
Enable-WindowsOptionalFeature -Online -All -FeatureName IIS-HttpRedirect
Enable-WindowsOptionalFeature -Online -All -FeatureName WCF-HTTP-Activation
Enable-WindowsOptionalFeature -Online -All -FeatureName WCF-HTTP-Activation45
I have recently come across the requirement to enable "Development time IIS support" in the Visual Studio Installer for .NET Core applications as per https://devblogs.microsoft.com/dotnet/development-time-iis-support-for-asp-net-core-applications/#development-time-iis-support. Is there a way I can do this from PowerShell?
I've figured it out...
choco install -y visualstudio2019-workload-netweb --package-parameters "--add Microsoft.VisualStudio.ComponentGroup.IISDevelopment"
References:
https://learn.microsoft.com/en-us/visualstudio/install/use-command-line-parameters-to-install-visual-studio?view=vs-2019
https://learn.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-professional?view=vs-2019&preserve-view=true#aspnet-and-web-development

How to enable Windows features "MSMQ Server" and "MSMQ Server Core" using PowerShell?

I am trying to enable Windows features "MSMQ Server" and "MSMQ Server Core" using PowerShell with the below command:
Enable-WindowsOptionalFeature -Online -FeatureName 'MSMQ-Server' -All -NoRestart
But the above command enables only the "MSMQ Server" and not "MSMQ Server Core". I want a PowerShell command which enables both "MSMQ Server" and "MSMQ Server Core" feature. Any help on this will be highly appreciated.
Thanks,
Mani Athreya S
If you want to enable all MSMQ features, you can run this command. For the record, I do not see a MSMS-Server-Core feature available in my up-to-date Server 2019 VM.
Get-WindowsOptionalFeature -FeatureName MSMQ* -Online |
Enable-WindowsOptionalFeature -Online -NoRestart -Verbose

Error while enabling IIS optional feature IIS-ASPNET and IIS-ManagementConsole

I am unable to enable the optional feature IIS-ASPNET and IIS-ManagementConsole. I keep getting the below error
Enable-WindowsOptionalFeature : One or several parent features are disabled so current feature can not be enabled.
At line:1 char:1
+ Enable-WindowsOptionalFeature -Online -FeatureName IIS-ASPNET
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Enable-WindowsOptionalFeature], COMException
+ FullyQualifiedErrorId : Microsoft.Dism.Commands.EnableWindowsOptionalFeatureCommand
What are the parent features of iis-aspnet and IIS-ManagementConsole that need to be enabled?
You need to pass the -All parameter to Enable-WindowsOptionalFeatures which installs the required parent features:
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ASPNET, IIS-ManagementConsole -All
To enable asp.net you also need to install the .net extensibility feature. you could try below PowerShell command:
Enable-WindowsOptionalFeature -Online -FeatureName IIS-NetFxExtensibility, IIS-NetFxExtensibility45,IIS-ASPNET, IIS-ASPNET45
To enable ManagementConsole you could use below command:
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ManagementConsole

Install hyperv cmdlet on workstation

I have a script that starts new HyperV VM's on a remote server using powershell
New-VM
Get-VM
I want to run this script on my desktop, however I get the following error.
the term 'new-vm' is not recognized as the name of a cmdlet
I can't figure out how to install the new-vm cmdlet on my workstation
Get-WindowsFeature
the target of the specified cmdlet cannot be a windows client-based operating system
Install-windowsFeature hyperv-
the target of the specified cmdlet cannot be a windows client-based operating system
I am very new to powershell, and don't do much with windows.
How can I install the cmdlet New-VM on a Windows 8 machine?
Update
Also tried the following.
Enable-WindowsOptionalFeature -Online -FeatureName Hyper-V-Tools
Enable-WindowsOptionalFeature -Online -FeatureName Hyper-V-PowerShell
I see hyperv tools in the following command
Get-WindowsOptionalFeature -Online | sort state
Microsoft-Hyper-V
Microsoft-Hyper-V-Tools-All
Microsoft-Hyper-V-Management-Powershell
Update 2
I almost got it installed, but it gives this error:
PS C:\Windows\system32> Enable-WindowsOptionalFeature -online -FeatureName Microsoft-Hyper-V-Management-Powershell
Enable-WindowsOptionalFeature : One or several parent features are disabled so current feature can not be enabled.
At line:1 char:1
+ Enable-WindowsOptionalFeature -online -FeatureName Microsoft-Hyper-V-Management- ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Enable-WindowsOptionalFeature], COMException
+ FullyQualifiedErrorId : Microsoft.Dism.Commands.EnableWindowsOptionalFeatureCommand
PS C:\Windows\system32>
Got it installed. The powershell cmdlet has parents that can be installed by adding -all.
Enable-WindowsOptionalFeature -online -FeatureName Microsoft-Hyper-V-Management-Powershell -all
You will need to reboot before the cmdlet is available.