Options

Red-Gate variables and Powershell scripts.

rjoinerrjoiner Posts: 9
edited August 14, 2013 6:49AM in Deployment Manager
Hi,

Couple of questions regarding Deployment Manager's use of PowerShell scripts.

1. Can you pass augments to any of the three different PowerShell scripts in a package from Deployment Manager?

2. Can any of the PowerShell scripts access any of the variables created in a package? If so how?

Thanks
Richard
Richard

Comments

  • Options
    Hi Richard.

    You can pass any information you need to a powershell script by setting a custom variable in your Deployment Manager Project. All of the variables you create in your project will be passed to your powershell script as string variables.

    Our documentation site has more information on variables and powershell
    Robin Hellen
    Test Engineer
    DLM Automation
  • Options
    Thanks Robin.

    I think I've setup my powershell scripts correctly to use the variables in Deployment Manager but when it's run they generate an error.

    When the scripts calls "Import-Module WebAdministration" a error is reported a little later

    "New-Item : Cannot retrieve the dynamic parameters for the cmdlet. Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))."

    This looks to be down to the fact that it's a 64-bit server that the powershell script is being run on and the agent is trying to run the script in the 32-bit version powershell .

    How can I get the agent to use the 64-bit version of powershell?
    Richard
  • Options
    csmithcsmith Posts: 138 Bronze 1
    Hi Richard

    Unfortunately the agent always runs in a 32-bit process at the moment, but this forum post details a workaround for the problem by using the Microsoft.Web.Administration rather than the WebAdministration module.

    Although not ideal, does this help?

    Best regards,
    Chris
    Divisional Development Lead
    Redgate Software
  • Options
    Thanks Chris.

    After a fair amount of trial an error I've gotten my powershell to use Microsoft.Web.Administration to create a web site and then a number of web applications under it when it's run directly on the server.

    Sadly when I package it up in a Deployment Manager package it fails to run the script and doesn't seem to pull or set the variables correctly.

    Variable set in Deployment manager:

    VAR_IISWebsiteName = rj-test.mydomain.com

    Powershell Script :

    ##Create website using the variable passed from the Deployment Manager
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
    $iis = New-Object Microsoft.Web.Administration.ServerManager
    $iis.Sites.Add("$VAR_IISWebsiteName", "https", "*:443:$VAR_IISWebsiteName", "C:\inetpub\$VAR_IISWebsiteName")
    $iis.CommitChanges()


    In the error log the I can see the variable being set:

    2013-08-14 07:29:21 DEBUG - [VAR_IISWebsiteName] = 'rj-test.mydomain.com'

    Then when my post deploy script is run the following happens:

    2013-08-14 07:30:19 INFO Calling PowerShell script: 'C:\inetpub\rj-test.mydomain.com\PostDeploy.ps1'
    2013-08-14 07:30:23 DEBUG Script 'C:\inetpub\rj-test.mydomain.com\PostDeploy.ps1' completed.
    2013-08-14 07:30:23 DEBUG Script output:
    2013-08-14 07:30:23 DEBUG
    GAC Version Location
    ---

    True v2.0.50727 C:\Windows\assembly\GAC_MSIL\Microsoft.Web.Administration\7.0.0.0__31bf3856ad364e35\Microsoft.Web.Administration.dll
    ERROR: Exception calling "Add" with "4" argument(s): "The site name cannot be empty."
    ERROR: At C:\inetpub\rj-test.mydomain.com\PostDeploy.ps1:7 char:15
    ERROR: + $iis.Sites.Add <<<< ("$VAR_IISWebsiteName", "https", "*:443:$VAR_IISWebsiteName", "C:\inetpub\$VAR_IISWebsiteName")
    ERROR: + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    ERROR: + FullyQualifiedErrorId : DotNetMethodException
    ERROR:

    To me that read that it hasn't set or picked up VAR_IISWebsiteName = rj-test.mydomain.com when the scripts runs.

    Clearly I'm not do something correctly or my understanding of how Deployment Manager uses variablies is incorrect.

    Help please... :)
    Richard
  • Options
    Hi Richard,

    Can you check the variable snapshot for the release please. From the project page, click the releases tab, and then click the view link for the release you deployed in the table. If VAR_IISWebsiteName variable is not present in the table, can you create a new release and try again.
    Robin Hellen
    Test Engineer
    DLM Automation
  • Options
    Thanks for teh quick response Robin.

    I'm afriad that the variable VAR_IISWebsiteName is listed in the table.
    Richard
  • Options
    Hi Richard,

    I have managed to reproduce your error here. What has happened is that we strip any non-alphanumeric characters from the variable names when we pass them to powershell. You can reference your variable as VARIISWebsiteName, or by using $DeploymentManagerParameters["VAR_IISWebsiteName"]
    Robin Hellen
    Test Engineer
    DLM Automation
  • Options
    Thanks for working that out. I'll give that a go.
    Richard
Sign In or Register to comment.