Scripting Installation of IIS

Hi, I am trying to write a powershell script that will install specific components of IIS on Server 2012 R2.

So far I have the following:

$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
  
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
  
if ($myWindowsPrincipal.IsInRole($adminRole))
    {
    # We are running "as Administrator" - so change the title and background color to indicate this
    $Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)"
    $Host.UI.RawUI.BackgroundColor = "DarkBlue"
    clear-host
    }
else
    {
    $newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";
    $newProcess.Arguments = $myInvocation.MyCommand.Definition;
    $newProcess.Verb = "runas";
    [System.Diagnostics.Process]::Start($newProcess);
    exit
    }
  
Import-Module ServerManager
Install-WindowsFeature Web-Server, Web-WebServer, Web-Common-Http, Web-Default-Doc, Web-Dir-Browsing, Web-Http-Errors, Web-Static-Content, Web-Health, Web-Http-Logging, Web-Performance, Web-Stat-Compression, Web-Security, Web-Filtering, Web-App-Dev, Web-Net-Ext, Web-Net-Ext45, Web-ASP, Web-Asp-Net, Web-Asp-Net45, Web-ISAPI-Ext, Web-ISAPI-Filter, Web-Mgmt-Tools, Web-Mgmt-Console
Read-Host -Prompt "Press Enter to exit"

However, when this script is run it fails the first time with the following error:

Install-WindowsFeature : The request to add or remove features on the specified server failed.
Installation of one or more roles, role services, or features failed.
The source files could not be downloaded.
Use the "source" option to specify the location of the files that are required to restore the feature. For more
information on specifying a source location, see http://go.microsoft.com/fwlink/?LinkId=243077. Error: 0x800f0906
At C:\Users\Matthew\Desktop\test.ps1:40 char:1
+ Install-WindowsFeature Web-Server, Web-WebServer, Web-Common-Http, Web-Default-D ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (@{Vhd=; Credent...Name=localhost}:PSObject) [Install-WindowsFeature],
    Exception
    + FullyQualifiedErrorId : DISMAPI_Error__Cbs_Download_Failure,Microsoft.Windows.ServerManager.Commands.AddWindowsF
   eatureCommand

If I then run the script again it will run successfully without an errors. Can anyone tell me where I am going wrong or how I can get the script to run successfully first time?

Thanks in advance,

Matt.

August 20th, 2015 4:15am

Did you try following the directions in  the message?

Usethe "source"option to specify the location of the files that are required to restore the feature. Formore
information on specifying a source location
,see http://go.microsoft.com/fwlink/?LinkId=243077.

Free Windows Admin Tool Kit Click here and download it now
August 20th, 2015 7:25am

Thanks for the response. I did look at the link and it is talking about repair/recovery and specifying files for this. I am not sure what files I am supposed to specify as the command runs correctly second time without me specifying a source. Therefore I assume the operating system has the necessary files already and does not require a external source. Its almost as if I need to load something into Powershell before running the command.

Also I hope to be able to run this command on various servers and am trying to avoid having to transfer large OS install files along with the script.


August 20th, 2015 7:58am

The problem is not scripting but is an issue with either your system or the order of your install.

Why are you specifying so many items when you could just specify the web server.  After the web server is installed you can then specify optional components.

You might also look at DSC which is better able to do structured installs.

Free Windows Admin Tool Kit Click here and download it now
August 20th, 2015 8:04am

Thanks for the information. I have tried Web Server on its own and this works fine. It seems to relate to the app development modules, but these still fail when installed after Web Server, so no luck on getting it to work.

I am going to investigate another route as I cannot get the script to run without errors on the first attempt. Thanks for your help.

August 20th, 2015 11:10am

Post here IIS.NET for more specific assistance with deployment.
Free Windows Admin Tool Kit Click here and download it now
August 20th, 2015 11:15am

Thanks for the response. I did look at the link and it is talking about repair/recovery and specifying files for this. I am not sure what files I am supposed to specify as the command runs correctly second time without me specifying a source. Therefore I assume the operating system has the necessary files already and does not require a external source. Its almost as if I need to load something into Powershell before running the command.

Also I hope to be able to run this command on various servers and am trying to avoid having to transfer large OS install files along with the script.


August 20th, 2015 11:57am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics