Tuesday 13 January 2015


Deploying WCF Service using Power shell Scripts (PS) /Desired State Configuration  (DSC ) through vNext Release Template in Microsoft Release Management

vNext Release Template

 
 
 
 

Custom Configuration Variables





Module_Copy.ps1

 

 

Configuration modulecopy {

 

    Node $ServerName

        {

                File ModuleContent

            {

                Ensure          = "Present"

                SourcePath      = $SourcePathBeforeBuildNo +"\"+ $BuildlNo +"\" + $SourcePathAfterBuildNo

                DestinationPath = $DestinationPath

                Recurse         = $true

                Type            = "Directory"

            }  

 

        }

 

}

 

modulecopy -DestinationPath $DestinationPath

 

===================================================================================

  

DSC_DeploymentScripts.ps1

 

Configuration Deploy {

 

Import-DscResource -Module xWebAuth

Import-DscResource -Module xWebSSLFlags

Import-DscResource -Module AppPoolServiceAccount

Import-DscResource -Module xWebAdministration

 

 

 

 

 

Node $ServerName

    {

 

    #install IIS

      #install IIS

 

         WindowsFeature IIS {

         Ensure = "Present"

         Name = "Web-Server"

 

     }

     WindowsFeature WebTools {

         Ensure = "Present"

         Name = "Web-Mgmt-Tools"

     }

         WindowsFeature WinAuth

        {

            Ensure = "Present"

            Name   = "web-Windows-Auth"            

        }

 

   #Install the ASP .NET 4.5 role

       # WindowsFeature AspNet40

       # {

       #     Ensure          = "Present"

       #     Name            = "Web-Asp-Net40"

       #     DependsOn       = "[WindowsFeature]IIS"

       # }       

       

        xWebAppPool NewWebAppPool

        {

            Name   = $NewWebAppPoolName

            Ensure = "Present"

           

            State  = "Started"

         

                        

           # DependsOn       = "[WindowsFeature]AspNet40"                        

        }

            

      

 

        AppPoolServiceAccount NewWebAppPoolServiceAccount

        {

            AppPoolName   = $NewWebAppPoolName

            UserName = $NewWebAppPoolServiceAccount

            Pwd=$NewWebAppPoolPassword

            IdentityType = $NewWebAppPoolIdentityType                

            Ensure = "Present"              

            DependsOn = "[xWebAppPool]NewWebAppPool"

          

        }

   

        

 

        #remove content

        File RemoveContent 

        { 

            Ensure          = "Absent" 

            DestinationPath = $DestinationPathforWebsite 

            Recurse         = $true 

            Type            = "Directory"

                     Force                = $true               

        }        

 

        # Copy the website content 

        File WebContent 

        { 

            Ensure          = "Present" 

             SourcePath      = $SourcePathBeforeBuildNo + "\"+ $BuildNo +"\" + $SourcePathAfterBuildNo

            

            DestinationPath = $DestinationPath 

            Recurse         = $true 

            Type            = "Directory"            

        }        

 

        # Create the new Website with HTTPS 

        xWebsite NewWebsite 

        { 

           Ensure          = "Present" 

            Name            = $WebsiteName 

            State           = "Started" 

            PhysicalPath    = $PhysicalPathForWebsite 

 

            BindingInfo     = MSFT_xWebBindingInformation 

                             { 

                               Protocol              = "HTTP" 

                               Port                  = 80

                               #CertificateThumbprint =$Node.Thumbprint

                               #CertificateStoreName  = "MY" 

                               IPAddress = $IPAddress

 

                             } 

                             ApplicationPool = $NewWebSiteAppPoolName

            DependsOn       = "[File]WebContent" 

      } 

 

       #Add Appliaction to the website created

       xWebApplication NewApplication

        {

               Ensure = "Present"

               Website = $WebsiteName

               WebAppPool = $NewWebAppPoolName

               PhysicalPath = $PhysicalPathForApplication

 

               Name =$WebAppName

 

        }

 

            

 

       xWebAuth WebSiteanonymousAuthenticationType

        {

            WebSiteName = $WebSiteName

            AuthenticationType = "anonymousAuthentication"

            Ensure = "Present"           

        }

 

       

 

      

       

   }

 

  

 }

 

 

 $CompleteSourcepath = $SourcePathBeforeBuildNo + "\"+ $BuildNo +"\" + $SourcePathAfterBuildNo

 Deploy -WebSiteName $WebsiteName -SourcePath $CompleteSourcepath -DestinationPath $DestinationPathforWebsite

 

 

 

================================================================

Webconfig.ps1

Configuration webconfigreplace {

 

 

 Import-Module WebAdministration

 

 

 Node $ServerName

    {

        File WebConfig 

        { 

            Ensure          = "Present" 

            SourcePath      = $SourcePathforconfigBeforeBuildNo +"\"+$BuildNo+"\"+$SourcePathforconfigAfterBuildNo

            DestinationPath = $DestinationPathforconfig 

            Recurse         = $true

            Type =          "Directory" 

            Force           =$true

        } 

 

              #xWebAuth WebSiteanonymousAuthenticationType

        #{

        #    WebSiteName = $Node.WebSiteName

        #    AuthenticationType = "anonymousAuthentication"

        #    Ensure = "Absent"           

        #}

 

       

        $appPool = Get-Item ("IIS:\AppPools\" + $NewWebAppPoolName)

        $appPool.managedRuntimeVersion = $DotNetFrameWorkVersion

        $appPool | Set-Item

       

    }

 

       

}

 

webconfigreplace -DestinationPath $DestinationPathforconfig

 

========================================================