I have one powershell script and that needs to be converted into a chef cookbook.I am unable to understand the conversion of powershell script. Need someone to please help me out oin this.
Function Change-SetParameterValue
{
param ([xml]$xmlDoc, [string]$paramName, [string]$newValue)
# XPath query
$checkParam = $xmlDoc.SelectSingleNode("/parameters/setParameter[@name='$paramName']")
if($checkParam -ne $null)
{
Echo "Setting '$paramName' with value '$newValue'"
$checkParam.Value=$newValue
}
else { Echo "Parameter '$paramName' not found!" }
}
#Builds VS proj
function DeployPrj($projName)
{
$zipFile = “$pkgLocation$projName.zip”
$paramFile = “$pkgLocation$projName.SetParameters.xml”
[xml]$xml = Get-Content $paramFile;
if($xml -eq $null) { Write-Error 'Unable to get XML document, please check directory path' -ErrorAction Stop }
#change the parameters file so the to set web.config settings for this instance
Change-SetParameterValue $xml 'IIS Web Application Name' $IISSiteName
$xml.Save($paramFile);
$arguments ="-source:package='$zipFile'",
"-dest:auto,computerName='$publishUrl',userName='$deployUser',password='$deployPassword',authType='Basic',includeAcls='False'",
"-setParamFile:$paramFile",
"-verb:sync",
"-enableRule:DoNotDeleteRule",
"-allowUntrusted"
& $MsDeplpoyExe $arguments
For your $MsDeployExe variable, you will most likely need to use double whacks ("\") for your value. Basically any variable that uses a single backslash will need to be converted to double-whacks.
A disclaimer: I haven’t used chef on Windows yet, so what I’m writing here is theoretical.
The fundamental difference between the PowerShell script and chef is that the powershell script describes actions - the steps to take. You would generally only run a PowerShell script once. Chef describes the desired state. You can run it as many times as you want, and it will only take actions the first time (or whenever something actually needs to be done). Very often, to actually accomplish what you need, you would embed a PowerShell script in Chef in the first place.
With that said, why not leave the PowerShell script intact (or extract bits and pieces, as needed) and write a Chef wrapper that calls it?
That said, your PowerShell script seems to pretty much just be a wrapper around msdeploy.exe? There is an msdeploy cookbook in the supermarket at https://supermarket.chef.io/cookbooks/msdeploy . It is several years old, but you could always clone it and use it as a starting point for what you actually need.
Can you please explain what EOH plays role in the powershell_script defination. I am getting an error while running cookbook is "Name space error initializer not defined::EOH