none
Conditional install of Web Server roles RRS feed

  • Question

  • I am trying to make a PS command that will check if my needed IIS roles are installed. if they are not, install them

    I have this partially working I tell it to get the name of the *web* role, and if the installstatus is Available, then to install.

    this is  an if/elseif statement.

    that statement is listed below:

    if (Get-WindowsFeature *web*|`
        where {($_.Name -match "web-server") -or`
        ($_.Name -match "web-http-redirect") -or`
        ($_.Name -match "web-dyn-compression") -or`
        ($_.Name -match "web-mgmt-tools") -or`
        ($_.Name -match "web-asp-net45") -and ($_.Installstate -eq "Installed")})
    {
     Write-Host "IIS Roles Exist"
    }
        
    elseif (Get-WindowsFeature *web*|`
            where {($_.Name -match "web-server") -or`
            ($_.Name -match "web-http-redirect") -or`
            ($_.Name -match "web-dyn-compression") -or`
            ($_.Name -match "web-mgmt-tools") -or`
            ($_.Name -match "web-asp-net45") -and ($_.Installstate -eq "Available")}| Install-WindowsFeature )
    {
     Write-Host "The Web Server Roles have been installed" -ForegroundColor Green
    }

    ###sorry for the compact script. the formatting looks prettier in my script###

    as stated this works...partially

    One a first run this works. The roles are installed, and if I rerun the script, it then displays that they Exists.

    What I tested next was to remove one of the roles and run the command again. I was hoping that it would reinstall only the missing roles. however, it returns that they exist. While this scenario will not happing in our environment, what if the PS windows crashes in the middle of the installed and only half the roles get installed. I wanted to rerun my script and only install what is missing.

    In short, I want it to do the following

    If searching A or B or C and they equal Installed, tell me they exist

    If searching for A or B Or C and they All equal Available, install them all

    If searching for A or B or C (A or B equal Installed, but C equals Available), install only that which is listed as Avaialble.

    let me know if this makes sense

    Thanks

    Ian

       

    Ian


    • Edited by The_Krayze Friday, May 18, 2018 7:38 PM
    • Moved by Bill_Stewart Friday, July 27, 2018 8:23 PM Abandoned
    Friday, May 18, 2018 7:00 PM

All replies

  • Please use the code posting tool provided on the edit bar.  Edit and fix your original post so that is is readable.


    \_(ツ)_/

    Friday, May 18, 2018 7:36 PM
  • thanks, that looks much better


    Ian

    Friday, May 18, 2018 7:39 PM
  • You have to start like this:

    if($featues = Get-WindowsFeature 'web*' | Where-Object{$_.Installed}){
           Write-Host 'Web server installed'
     }


    \_(ツ)_/


    • Edited by jrv Friday, May 18, 2018 7:46 PM
    Friday, May 18, 2018 7:46 PM