Red Gate forums :: View topic - Red-Gate variables and Powershell scripts.
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
Deployment Manager
Deployment Manager forum

Red-Gate variables and Powershell scripts.

Search in Deployment Manager forum
Post new topic   Reply to topic
Jump to:  
Author Message
rjoiner



Joined: 03 Jul 2013
Posts: 7
Location: England

PostPosted: Tue Aug 13, 2013 9:30 am    Post subject: Red-Gate variables and Powershell scripts. Reply with quote

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
Back to top
View user's profile Send private message
robin



Joined: 16 Nov 2007
Posts: 15

PostPosted: Tue Aug 13, 2013 10:15 am    Post subject: Reply with quote

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
Deployment Manager
Back to top
View user's profile Send private message
rjoiner



Joined: 03 Jul 2013
Posts: 7
Location: England

PostPosted: Tue Aug 13, 2013 4:07 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
csmith



Joined: 30 Jun 2011
Posts: 114
Location: Cambridge

PostPosted: Tue Aug 13, 2013 4:45 pm    Post subject: Reply with quote

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
_________________
Chris Smith
Project Manager
Deployment Manager
Back to top
View user's profile Send private message
rjoiner



Joined: 03 Jul 2013
Posts: 7
Location: England

PostPosted: Wed Aug 14, 2013 8:39 am    Post subject: Reply with quote

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: (Smile [], 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... Smile
_________________
Richard
Back to top
View user's profile Send private message
robin



Joined: 16 Nov 2007
Posts: 15

PostPosted: Wed Aug 14, 2013 9:33 am    Post subject: Reply with quote

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
Deployment Manager
Back to top
View user's profile Send private message
rjoiner



Joined: 03 Jul 2013
Posts: 7
Location: England

PostPosted: Wed Aug 14, 2013 9:45 am    Post subject: Reply with quote

Thanks for teh quick response Robin.

I'm afriad that the variable VAR_IISWebsiteName is listed in the table.
_________________
Richard
Back to top
View user's profile Send private message
robin



Joined: 16 Nov 2007
Posts: 15

PostPosted: Wed Aug 14, 2013 11:36 am    Post subject: Reply with quote

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
Deployment Manager
Back to top
View user's profile Send private message
rjoiner



Joined: 03 Jul 2013
Posts: 7
Location: England

PostPosted: Wed Aug 14, 2013 11:49 am    Post subject: Reply with quote

Thanks for working that out. I'll give that a go.
_________________
Richard
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group