Error when trying to stop website via powershell

I need to stop a website in the postdeploy-script due to some files I need to copy being locked. The script looks like this:

Import-Module WebAdministration
$websiteName = "Microsoft Dynamics CRM"
Stop-WebSite $websiteName

It works fine if I run it directly in an elevated PowerShell, but running under Octopus, I get a
ERROR: Stop-Website : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

Has anyone else had this problem?

Hi,

Can you let me know what user account your Tentacle windows service is running under? My guess is that the user might not have access to configure IIS.

Paul

It is running as local system.

I have temporarily changed the script to do a full iisreset, and that works. I would have expected the same (lack of) permissions to apply?

Hi Niko,

My only guess is that IISReset is just bouncing the services, while Stop-Website is doing something more. Stop-Website is probably updating the IIS configuration files to mark the site as “Stopped” so that in the event of a computer reboot the website doesn’t come back online (since you are “stopping”, not simply “resetting”). Perhaps Local System doesn’t have permission to write to these files, but it does have permission to restart a service - just a guess.

Paul