0

I have created a Windows Server 2012 R2 VM using azure ARM template. I have successfully configured IIS on it. I have to deploy ASP .Net web sites to the IIS on the VM. Now I am facing problem how to deploy the application in IIS server using powershell script.

I am using the below script to download the application from Azure blob storage and saving in "C:\WindowsAzure\WebApplication.zip" folder. The script is working till downloading and copying to "C:\WindowsAzure\WebApplication.zip" folder. But it's not deploying to "C:\inetpub\wwwroot" folder.

Configuration Main
{
  param (
  $MachineName,
  $WebDeployPackagePath,
  $UserName,
  $Password
  )

  Node ($MachineName)
  {

     WindowsFeature WebServerRole

        {



            Name = "Web-Server"

            Ensure = "Present"


            }


        WindowsFeature WebAppDev

        {

            Name = "Web-App-Dev"

            Ensure = "Present"


            DependsOn = "[WindowsFeature]WebServerRole"

            }

           WindowsFeature WebAspNet45

        {

            Name = "Web-Asp-Net45"

            Ensure = "Present"

            Source = $Source

            DependsOn = "[WindowsFeature]WebServerRole"

            }

        WindowsFeature WebNetExt35

        {

            Name = "Web-Net-Ext"

            Ensure = "Present"

            DependsOn = "[WindowsFeature]WebServerRole"

            }

           WindowsFeature WebNetExt45

        {

            Name = "Web-Net-Ext45"

            Ensure = "Present"

            DependsOn = "[WindowsFeature]WebServerRole"

            }

          WindowsFeature WebFtpServer
          {
                Name = "Web-Ftp-Server"

            Ensure = "Present"

            DependsOn = "[WindowsFeature]WebServerRole"

          }

          WindowsFeature WebMgmtCompat
          {
            Name = "Web-Mgmt-Compat"

            Ensure = "Present"

            DependsOn = "[WindowsFeature]WebServerRole"

          }

        WindowsFeature WebISAPIExt

        {

            Name = "Web-ISAPI-Ext"

            Ensure = "Present"


            DependsOn = "[WindowsFeature]WebServerRole"

        }

        WindowsFeature WebISAPIFilter

        {

            Name = "Web-ISAPI-Filter"

            Ensure = "Present"


            DependsOn = "[WindowsFeature]WebServerRole"

        }

        WindowsFeature WebLogLibraries

        {

            Name = "Web-Log-Libraries"

            Ensure = "Present"

            DependsOn = "[WindowsFeature]WebServerRole"

        }

        WindowsFeature WebRequestMonitor

        {

            Name = "Web-Request-Monitor"

            Ensure = "Present"

            DependsOn = "[WindowsFeature]WebServerRole"

        }

        WindowsFeature WebMgmtTools

        {

            Name = "Web-Mgmt-Tools"

            Ensure = "Present"

            DependsOn = "[WindowsFeature]WebServerRole"

        }

        WindowsFeature WebMgmtConsole

        {

            Name = "Web-Mgmt-Console"

            Ensure = "Present"

            DependsOn = "[WindowsFeature]WebServerRole"

        }

        WindowsFeature WAS

        {

            Name = "WAS"

            Ensure = "Present"

            DependsOn = "[WindowsFeature]WebServerRole"

        }

        WindowsFeature WASProcessModel

        {

            Name = "WAS-Process-Model"

            Ensure = "Present"

            DependsOn = "[WindowsFeature]WebServerRole"

        }

        WindowsFeature WASNetEnvironment

        {

            Name = "WAS-NET-Environment"

            Ensure = "Present"

            DependsOn = "[WindowsFeature]WebServerRole"

        }

        WindowsFeature WASConfigAPIs

        {

            Name = "WAS-Config-APIs"

            Ensure = "Present"

            DependsOn = "[WindowsFeature]WebServerRole"

        }

   #script block to download WebPI MSI from the Azure storage blob
    Script DownloadWebPIImage
    {
        GetScript = {
            @{
                Result = "WebPIInstall"
            }
        }
        TestScript = {
            Test-Path "C:\WindowsAzure\wpilauncher.exe"
        }
        SetScript ={
            $source = "http://go.microsoft.com/fwlink/?LinkId=255386"
            $destination = "C:\WindowsAzure\wpilauncher.exe"
            Invoke-WebRequest $source -OutFile $destination

        }
    }

    Package WebPi_Installation
    {
        Ensure = "Present"
        Name = "Microsoft Web Platform Installer 5.0"
        Path = "C:\WindowsAzure\wpilauncher.exe"
        ProductId = '4D84C195-86F0-4B34-8FDE-4A17EB41306A'
        Arguments = ''
    }

    Package WebDeploy_Installation
    {
        Ensure = "Present"
        Name = "Microsoft Web Deploy 3.5"
        Path = "$env:ProgramFiles\Microsoft\Web Platform Installer\WebPiCmd-x64.exe"
        ProductId = ''
        #Arguments = "/install /products:ASPNET45,ASPNET_REGIIS_NET4,NETFramework452,NETFramework4Update402,NetFx4,NetFx4Extended-ASPNET45,NetFxExtensibility45,DefaultDocument,DirectoryBrowse,StaticContent,StaticContentCompression,WDeploy  /AcceptEula"
        Arguments = "/install /products:WDeploy  /AcceptEula"
        DependsOn = @("[Package]WebPi_Installation")
    }


    Script DeployWebPackage
    {
            GetScript = {
                @{
                    Result = ""
                }
            }
            TestScript = {
                $false
            }
            SetScript ={

                $WebClient = New-Object -TypeName System.Net.WebClient
                $Destination= "C:\WindowsAzure\WebApplication.zip" 
                $WebClient.DownloadFile($using:WebDeployPackagePath,$destination)
                $Argument = '-source:package="C:\WindowsAzure\WebApplication.zip"' + ' -dest:auto,ComputerName="localhost",'+"username=$using:UserName" +",password=$using:Password"
                $MSDeployPath = (Get-ChildItem "HKLM:\SOFTWARE\Microsoft\IIS Extensions\MSDeploy" | Select -Last 1).GetValue("InstallPath")
                Start-Process "$MSDeployPath\msdeploy.exe" $Argument -Verb runas

            }

        }

     }

}

Please give me some idea.

gariepy
  • 3,576
  • 6
  • 21
  • 34
  • What's the error message you are getting? Is it showing nothing? – Jack Zeng Mar 30 '16 at 05:06
  • When I am accessing my webapplication like (http:// /WebApplication) it's showing "No directory found". I logged in to that VM and checked there is no webapplication folder under inetpub\wwwroot directory. So, Please give me some idea, that how can I deploy my ASP.net application in IIS server using script. – Sandhyarani Sahoo Mar 30 '16 at 05:52
  • Have your tried to deploy your web app with Visual Studio? Get more information in [Creating a virtual machine for a web application with Visual Studio](https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-classic-web-app-visual-studio/). I am not sure if you have your VM properly configured. – Jack Zeng Mar 30 '16 at 06:33
  • Yes, My application is working fine in Visual Studio. Whatever script I am using, I have taken that from Github. All the script is working properly for one particular application mentioned in Github. But when I am deploying my application it's not working. I have tried with 2-3 application from internet, still it's not working. I am using the below github URL for my application deployment in VM. (https://github.com/Azure/azure-quickstart-templates/tree/master/201-web-app-vm-dsc). – Sandhyarani Sahoo Mar 30 '16 at 07:45
  • I know your app works properly in Visual Studio. What I am asking is that whether you have tried to deploy the app to your VM in Visual Studio, just like deploying the app to Azure App Service. If you want to deploy a web app to an Azure VM, you need to enable IIS and Web Deploy. If you created your VM through Visual Studio, you can do that while creating the VM. – Jack Zeng Mar 30 '16 at 07:46
  • Thanks a lot for your help. I got to know, why my application is not working. Actually I am not replacing the web.config file with my own DB details. I logged in to the Azure VM. Both IIS and web deploy is properly installed . Now I have to edit the web.config file inside the powershell script. Please give me some idea in powershell script so that I can edit my .config file. – Sandhyarani Sahoo Mar 31 '16 at 10:33

0 Answers0