Issue with execution of Octopus PS script

Using Octopus to create a website and am getting the attached error with the Octopus.Features.IISWebSite_BeforePostDeploy.ps1 script when it’s trying to create the site.

Error message is: Windows PowerShell is in NonInteractive mode. Read and Prompt functionality is not available.

I am also having same exact issue, please keep me posted about the solution. Thanks

Hi,

Can you log in to the remote machine that is experiencing the problem, and run the following PowerShell script, and tell me what happens?

Import-Module WebAdministration

# Create a site with this name - you should delete it afterwards
$webSiteName = "Bar"

pushd IIS:\
$sitePath = ("IIS:\Sites\" + $webSiteName)
$site = Get-Item $sitePath -ErrorAction SilentlyContinue
if (!$site) { 
    Write-Host "Site `"$WebSiteName`" does not exist, creating..." 
    $id = (dir iis:\sites | foreach {$_.id} | sort -Descending | select -first 1) + 1
    new-item $sitePath -bindings @{protocol="http";bindingInformation=":81:od-temp.example.com"} -id $id -physicalPath $webRoot
}
popd

Note that you’ll have to run it from an elevated PowerShell session.

The problem seems to be that due to configuration on the machine, for some reason the call to New-Item is resulting in PowerShell prompting for more information, which it can’t do. I need to know what it is prompting for.

Thanks!

Paul

I ran the script and it created the site, but I also got error on the first Import statement. Here is the result of script execution:

`PS C:\Users\naveedm> Import-Module WebAdministration
Import-Module : File C:\windows\system32\WindowsPowerShell\v1.0\Modules\WebAdministration\WebAdministrationAliases.ps1
cannot be loaded because the execution of scripts is disabled on this system. Please see “get-help about_signing” for m
ore details.
At line:1 char:14

  • Import-Module <<<< WebAdministration
    • CategoryInfo : NotSpecified: (:slight_smile: [Import-Module], PSSecurityException
    • FullyQualifiedErrorId : RuntimeException,Microsoft.PowerShell.Commands.ImportModuleCommand

PS C:\Users\naveedm> # Create a site with this name - you should delete it afterwards
PS C:\Users\naveedm> $webSiteName = “Bar”
PS C:\Users\naveedm> pushd IIS:
PS IIS:> $sitePath = ("IIS:\Sites" + $webSiteName)
PS IIS:> $site = Get-Item $sitePath -ErrorAction SilentlyContinue
PS IIS:> if (!$site) {

Write-Host "Site `"$WebSiteName`" does not exist, creating..."
$id = (dir iis:\sites | foreach {$_.id} | sort -Descending | select -first 1) + 1
new-item $sitePath -bindings @{protocol="http";bindingInformation=":81:od-temp.example.com"} -id $id -physicalPat

h $webRoot

}
popd

Site “Bar” does not exist, creating…

Name ID State Physical Path Bindings


Bar 2 Started http :81:od-temp.example.com`

I saved this script as Ocottest.ps1 and ran it from an elevated PS windows and here are the results:

[cid:image001.png@01CF3D09.30B286C0]

Site does in fact now exist.

Note: I deleted the bar site and tried just copy-paste into the PowerShell window and it paused at this point:
[cid:image002.png@01CF3D0D.F8E6FAF0]

After pressing Enter, it completed the site creation:
[cid:image003.png@01CF3D0D.F8E6FAF0]

From: Mein, Robert - IST contractor
Sent: Tuesday, March 11, 2014 9:06 AM
To: ‘Paul Stovell’
Subject: RE: Issue with execution of Octopus PS script [Problems #16549]

I saved this script as Ocottest.ps1 and ran it from an elevated PS windows and here are the results:

[cid:image004.png@01CF3D0D.F8E6FAF0]

Site does in fact now exist.

Hi Robert,

I have a hunch that your server might have a $ConfirmPreference that is higher than we expect. You can read more about this here:

http://blogs.msdn.com/b/powershell/archive/2006/12/15/confirmpreference.aspx

It’s possible that your user account has a different preference to the value used by the account that Tentacle runs under.

Is your Tentacle service configured to run under a custom user account?

Could you create a script step that looks like this, and add it as a step to your project in Octopus so that it gets run on the remote machine, and let me know what it says?

Write-Host $ConfirmPreference

Thanks,

Paul

[cid:image001.png@01CF3DCE.482D2830]

The tentacle service is running as “Local System”.

image001.png

Hi Robert,

On your Tentacle, could you try replacing the contents of this file:

C:\Program Files\Octopus Deploy\Tentacle\Scripts\Octopus.Features.IISWebSite_BeforePostDeploy.ps1

With the contents here:

And tell me how that goes?

Paul

I followed your instructions and saw no difference. I then noticed the location where the scripts was actually being run (C:\Octopus2\Applications.Tentacle\Octopus.Tentacle\2.2.1.1261_1\Scripts) was different than the location you listed so I copied the new script there and deployed a release and got the following error:

[cid:image001.png@01CF41BD.863CA720]

Looks like a syntax error with an errant “-“. I removed that and redeployed. Received a new error:

[cid:image002.png@01CF41BE.5A17BAD0]

Hi Robert,

Thanks for this. I’ve updated the script - could you try this version?

Paul

Updated the PS script. Got the same error:

[cid:image001.png@01CF429C.A5555C80]

I’ve been invesitgating this via another ticket and have a bit of a thory; if you want to cut straight to the chase here’s an updated script:

Details - it would seem that -Confirm is handled by PowerShell, while -Force (added in the version above) is passed to the underlying provider (e.g. the WebAdministration implementation).

A badly-behaved module that ignores -NonInteractive might still respect -Force.

I think we’re hitting this because the target of the command does already exist but isn’t being retrieved, and we use -ErrorAction “SilentlyContinue” to steamroll over this.

Apologies if this is yet another dead end, but seems like it is worth a shot.

Hope this helps,
Nick

Thanks for the input Nicholas. I updated the appropriate script and had no better luck. Still getting the same error:

[cid:image003.jpg@01CF4CF0.14D37C60]

Thanks for the update Robert. At this stage I’m pretty stumped about why it would be prompting. We’re going to make a change in the next release to allow you to disable the NonInteractive flag and hopefully see why it is prompting:

I’m sorry I don’t have any other solution at present, we should have the new release out in a week or so.

Paul

I am having the exact same problem. I will look into this thread in detail but just thought I’d share my setup: My project that has been successfully deployed many times on many machines. Today I was going to install the project on a new machine. Tentacle healtch seems fine, latest version of Calamari, but deploy fails with the exact same error message as on the top of this page.

Hi Emil,

Thanks for reaching out. The error at the top of the thread makes reference to our old IIS deploy steps. In 3.4.7 we introduced our latest version of them, which is basically a complete overhaul: https://octopus.com/blog/virtual-dir-iis-windows-service-steps

If you are not using these new steps, I recommend you to give them a try and see if you still get this error using them.

Regards,
Dalmiro