Deploying Web Site on IIS7 OS:Windows 2008 Standard

Hi,

when we tried to deploy our web site to IIS 7 the deployment task failed with the error:

`Import-Module : The specified module ‘WebAdministration’ was not loaded because
Error 14:43:35
no valid module file was found in any module directory.
Error 14:43:35
At C:\Program Files\Octopus Deploy\Tentacle\Scripts\Octopus.Features.IISWebSite
Error 14:43:35
_BeforePostDeploy.ps1:49 char:14
Error 14:43:35

  • Import-Module <<<< WebAdministration
    Error 14:43:35
    • CategoryInfo : ResourceUnavailable: (WebAdministration:String)
      Error 14:43:35
      [Import-Module], FileNotFoundException
      Error 14:43:35
    • FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Comm
      Error 14:43:35
      ands.ImportModuleCommand
      Fatal 14:43:35
      PowerShell script returned a non-zero exit code: 1`

which is expected as WebAdministration for IIS7 is SnapIn instead of module as in IIS 7.5.

we ended up modifying the script Octopus.Features.IISWebSite_BeforePostDeploy and replaced:
Line 49: Import-Module WebAdministration
with
if ((Get-Module -ListAvailable | ForEach-Object {$_.Name}) -contains $WebAdministrationModule) { Import-Module WebAdministration } elseif ((Get-PSSnapin -Registered | ForEach-Object {$_.Name}) -contains $WebAdministrationModule) { Add-PSSnapIn WebAdministration; } else { throw "WebAdministration module/snap-in not installed" }

did we overlooked some setting or is it actually a bug in the deployment script ?

Hi Ian,

Thanks for getting in touch; this has been fixed in the 2.4 series - we’ll try both the snap-in and the module now.

Regards,
Nick

I was able to get this working just yesterday in 2.3.x by modifying the Octopus IIS7 deployment script, but there ended up being other things that failed down the line. I’m unsure if they were related to the environment or differences in the powershell functionality between Windows versions. I can pasted the snippet below over the top of the ‘Import-Module WebAdministration’ line in the powershell file.

$ModuleName = "WebAdministration"
$ModuleLoaded = $false
$LoadAsSnapin = $false

if ($PSVersionTable.PSVersion.Major -ge 2)
{
    if ((Get-Module -ListAvailable | ForEach-Object {$_.Name}) -contains $ModuleName)
    {
        Import-Module $ModuleName
        if ((Get-Module | ForEach-Object {$_.Name}) -contains $ModuleName)
        {
            $ModuleLoaded = $true
        }
        else
        {
            $LoadAsSnapin = $true
        }
    }
    elseif ((Get-Module | ForEach-Object {$_.Name}) -contains $ModuleName)
    {
        $ModuleLoaded = $true
    }
    else
    {
        $LoadAsSnapin = $true
    }
}
else
{
    $LoadAsSnapin = $true
}

if ($LoadAsSnapin)
{
    if ((Get-PSSnapin -Registered | ForEach-Object {$_.Name}) -contains $ModuleName)
    {
        Add-PSSnapin $ModuleName
        if ((Get-PSSnapin | ForEach-Object {$_.Name}) -contains $ModuleName)
        {
            $ModuleLoaded = $true
        }
    }
    elseif ((Get-PSSnapin | ForEach-Object {$_.Name}) -contains $ModuleName)
    {
        $ModuleLoaded = $true
    }
}

I pulled the above code from here:

Import-Module WebAdministration error

Hello,

Im using version 2.4.10.235 and get something like the message below. The builds get to the server fine. The issue is deploying to IIS. Seems the powershell script cant find the website folders. I have a pretty standard install of IIS. Do I have to modify that file to get it to work?

This is the error :

Push-Location : Cannot find drive. A drive with the name ‘IIS’ does not exist.
Error 03:57:43
At C:\Accounts\Octopus Deploy\Tentacle\Scripts\Octopus.Features.IISWebSite_Befo
Error 03:57:43
rePostDeploy.ps1:136 char:6
Error 03:57:43

  • pushd <<<< IIS:
    Error 03:57:43
  • CategoryInfo : ObjectNotFound: (IIS:String) [Push-Location], Dr
    Error 03:57:43
    iveNotFoundException
    Error 03:57:44
  • FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.Push
    Error 03:57:44
    LocationCommand
    Fatal 03:57:44
    PowerShell script returned a non-zero exit code: 1 Tentacle version 2.5.4.280

I resolved this by installing the snappin and following a few examples from above.

Now I am trying to make sure the nuget package deploys into the proper IIS directory. Currently it just puts the content/lib folders.

Hi Eric,

I am glad you were able to resolve your issue. As for your packages, they deploy with the same file structure for which they were created - hopefully this will help you find the issue.

Vanessa

Hi,

I am getting the same error
Push-Location : Cannot find drive. A drive with the name ‘IIS’ does not exist.
version: 2.6.0.778
Installed Octopus in Windows server enterprise (sp2) 64bit machine
I have tried to install the snappin using these commands

Add-PSSnapin WebAdministration -ErrorAction SilentlyContinue

Import-Module WebAdministration -ErrorAction SilentlyContinue

but not resolved. Then I use the above code to import the snapin, but it gives an error
WebAdministration module/snap-in not installed

Getting this error –

Push-Location : Cannot find drive. A drive with the name ‘IIS’ does not exist.
At C:\Program Files\Octopus Deploy\Tentacle\Scripts\Octopus.Features.IISWebSite
_BeforePostDeploy.ps1:217 char:6

  • pushd <<<< IIS:\
    • CategoryInfo : ObjectNotFound: (IIS:String) [Push-Location], Dr
      iveNotFoundException
    • FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.Push
      LocationCommand
      PowerShell script returned a non-zero exit code: 1
      Tentacle version 2.6.0.778

Hi,

The PS Snap-In comes built in with IIS since version 7.5 (windows 2008 R2) according to Microsoft: http://www.iis.net/learn/install/installing-iis-7/installing-iis-7-and-above-on-windows-server-2008-or-windows-server-2008-r2

You can manually install the Snap-in on IIS 7.0 from the following link, but i would recommend to investigate first if this is applicable to your Windows version

http://www.iis.net/downloads/microsoft/powershell

Thanks!

Dalmiro

Hi

Thanks to reply! Yes I have manually installed the Snap-in and it works.
Thanks again

Regards,
Debolina

Just a note; replacing the Import-Module line with:

Add-PSSnapin WebAdministration

Worked for me. This is on Octopus 2.5.

Hello,

I had this issue on V3.1.5. Can you please help?


Deploying package ‘D:\Octopus\Files\Demo.XBanking.1.1.0.0.nupkg-8420f262-7eac-4f79-8389-6e94b49060f5’ to machine 'https://xxx:10933/'
17:12:41Info
Deploying package: D:\Octopus\Files\Demo.XBanking.1.1.0.0.nupkg-8420f262-7eac-4f79-8389-6e94b49060f5
17:12:42Info
Transforming ‘D:\Octopus\Applications\Test - Local\Demo.XBanking\1.1.0.0_1\Web.config’ using ‘D:\Octopus\Applications\Test - Local\Demo.XBanking\1.1.0.0_1\Web.Release.config’.
17:12:43Error
Push-Location : Cannot find drive. A drive with the name ‘IIS’ does not exist.
17:12:43Error
At D:\Octopus\Applications\Test - Local\Demo.XBanking\1.1.0.0_1\Octopus.Feature
17:12:43Error
s.IISWebSite_BeforePostDeploy.ps1:214 char:6
17:12:43Error

  • pushd <<<< IIS:
    17:12:43Error
    • CategoryInfo : ObjectNotFound: (IIS:String) [Push-Location], Dr
      17:12:43Error
      iveNotFoundException
      17:12:43Error
    • FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.Push
      17:12:43Error
      LocationCommand
      17:12:43Error
      17:12:43Error
      Script ‘D:\Octopus\Applications\Test - Local\Demo.XBanking\1.1.0.0_1\Octopus.Features.IISWebSite_BeforePostDeploy.ps1’ returned non-zero exit code: 1
      17:12:43Error
      Running rollback conventions…
      17:12:43Error
      Script ‘D:\Octopus\Applications\Test - Local\Demo.XBanking\1.1.0.0_1\Octopus.Features.IISWebSite_BeforePostDeploy.ps1’ returned non-zero exit code: 1
      17:12:43Error
      The remote script failed with exit code 1

Hi Fred,

Thanks for reaching out. What OS, IIS and Powershell version are you running on that Tentacle? Did it use to work with prior versions of Octopus?

Please also send us the full deployment log to support@Octopus.com . You can also attach it here if you dont mind the log being public.

http://docs.octopusdeploy.com/display/OD/Get+the+raw+output+from+a+task

Thanks!

Dalmiro

Hi Dalmiro,

I found out that the Windows 7 seems not supported through the Octopus requirements. I switched to work on Windows 2008 and it’s fine now.

Thanks for replying

I’m getting a similar error when I’m trying to install an offline package drop, on Windows 2012 R2 Standard, x64, with Octopus 3.2.13.

The target web application is an IIS website.
I’m running this deployment for testing purposes, on my account that is also member of local Administrators.
When I’m running the same deployment against a Tentacle, that runs as LocalSystem, everything works well.

pushd : Cannot find drive. A drive with the name ‘IIS’ does not exist.
At C:\inetpub\wwwroot\MyWebSite\Octopus.Features.IISWebSite_BeforePostDeploy.ps1:264 char:1

  • pushd IIS:\
  •   + CategoryInfo          : ObjectNotFound: (IIS:String) [Push-Location], DriveNotFoundException
      + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.PushLocationCommand
    
    

Could it be caused by a lack of, or incorrect permissions?

Hi Daniel,

The message Cannot find drive. A drive with the name 'IIS' does not exist. Is usually related to problems loading the WebAdministration module. In this case it could mean any of these things:

  • The machine where you are running this offline package has IIS installed, but it doesnt have the webadministration module on it. Though if you say the deployment runs fine when running it from a Tentacle, I’d say the module is on the machine already.

  • You user doesn’t have enough permissions to import this module. Running import-module webadministration from a Powershell (admin) console could clear this up for you.

Regards,
Dalmiro

Thanks,

That fixed the error.