Get-Item : Cannot find path 'IIS:\Sites\DeployWarmupSite' because it does not exist

I have this script that starts a site in IIS.

Import-Module WebAdministration
$site = Get-Item “IIS:\Sites\DeployWarmupSite”
$site.Start()

When I run the script locally on the server it works. It also works when running it in the context of Tentacle.exe on the server. However when the script runs from octopus I get this error:

Get-Item : Cannot find path ‘IIS:\Sites\DeployWarmupSite’ because it does not exist.
At C:\Windows\system32\config\systemprofile\AppData\Local\Tentacle\Temp\cb53b94
f-9ab3-4a9c-be15-bfd2f523049a.ps1:7 char:17

  • $site = Get-Item <<<< “IIS:\Sites\DeployWarmupSite”
  • CategoryInfo : ObjectNotFound: (IIS:\Sites\DeployWarmupSite:String) [Get-Item], ItemNotFoundException
  • FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand

Hi Sigve,

Thanks for getting in touch! We have a library step specifically for starting IIS sites in case you want to try it out

https://library.octopusdeploy.com/#!/step-template/actiontemplate-iis-website-start

If you want to stick with using the script, the first thing i would check is if the account running the tentacle service has admin right on that VM. Could you try remoting into the tentacle with this account and running the script?

Thanks!

Dalmiro

The script I’m runing is identical to the library just without the output stuff.

The user the service is running under has admin rights and as I mentioned in my original post I have tried running the script locally on the server with success. Both in the poweshell command window and in the regular command window running it in context of Tentacle.exe

The weird thing is that the deploy step is successful even though it runs the “Octopus.Features.IISWebSite_BeforePostDeploy.ps1” script which contains the exact same way of getting a site in IIS.

Hi,

Could you try running your exact command on the same tentacle using the Script Console in Octopus? This is usually the best way to troubleshoot problems with custom scripts, as it runs them almost identically as they would run during a deployment process.

If that doesnt work, try running these commands on the Script console like:

Get-module -listavailable (to make sure the IIS module is being loaded)

Get-Psdrive (to make sure the IIS drive is mounted)

Get-website (to make sure that the website can be found)

Let me know how those tests go

Dalmiro

This was my results:

Get-module -listavailable
ModuleType Version Name ExportedCommands


Manifest 1.0.0.0 ADRMS {Update-ADRMS, Uni…
Manifest 1.0.0.0 AppLocker {Set-AppLockerPoli…
Manifest 1.0 BestPractices {Get-BpaModel, Inv…
Manifest 1.0.0.0 BitsTransfer {Add-BitsFile, Rem…
Manifest 1.0.0.0 CimCmdlets {Get-CimAssociated…
Manifest 3.0.0.0 Microsoft.PowerShell.Diagnostics {Get-WinEvent, Get…
Manifest 3.0.0.0 Microsoft.PowerShell.Host {Start-Transcript,…
Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Content, Clea…
Manifest 3.0.0.0 Microsoft.PowerShell.Security {Get-Acl, Set-Acl,…
Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Format-List, Form…
Manifest 3.0.0.0 Microsoft.WSMan.Management {Disable-WSManCred…
Binary 1.0 PSDesiredStateConfiguration {Set-DscLocalConfi…
Script 1.0.0.0 PSDiagnostics {Disable-PSTrace, …
Binary 1.1.0.0 PSScheduledJob {New-JobTrigger, A…
Manifest 2.0.0.0 PSWorkflow {New-PSWorkflowExe…
Manifest 1.0.0.0 PSWorkflowUtility Invoke-AsWorkflow
Manifest 1.0.0.0 ServerManager {Get-WindowsFeatur…
Manifest 1.0.0.0 TroubleshootingPack {Get-Troubleshooti…
Manifest 1.0.0.0 WebAdministration {Start-WebCommitDe…
Directory: C:\Program Files (x86)\Microsoft SQL Server\120\Tools\PowerShell
\Modules
ModuleType Version Name ExportedCommands


Manifest 1.0 SQLASCMDLETS {Add-RoleMember, B…
Manifest 1.0 SQLPS {Backup-SqlDatabas…

Get-Psdrive
Info 21:29:17
Name Used (GB) Free (GB) Provider Root


A FileSystem A:\
Alias Alias
C 36,28 13,62 FileSystem C:\
Cert Certificate \
D 18,80 21,20 FileSystem D:\
Env Environment
Function Function
HKCU Registry HKEY_CURRENT_USER
HKLM Registry HKEY_LOCAL_MACHINE
Variable Variable
WSMan WSMan
Z FileSystem Z:\

Get-website
Name ID State Physical Path Bindings


BI4 2 Started D:\xxx\Sites\xxx\1.0 http :80:
.2881.113 http *:80:xxx.no
DeployWarmupSite 3 Started D:\xxx\Sites\xxx\1.0 http :1111:
.2881.113
#{WarmupSiteName 4 Started D:\xxx\Sites\xxx\1.0 http :81:od-tem
} .2876.108 p.example.com

I figured it out.

I ran the following in the Script Console and now it works.

Import-Module ServerManager
Add-WindowsFeature Web-Scripting-Tools

Thanks, Sigve!

Thanks for this post. It helped me too!

Notice:

This issue has been closed due to inactivity. If you encounter the same or a similar issue and require help, please open a new discussion (if we asked for logs or extra details in this thread, consider including them in the new thread). If you are the creator of this thread and believe it should not be closed let us know via our support email.