I have a config XML , from which I am trying to read the information in Powershell script. The Powershell script takes input from user and then would need to navigate to each of the path. My configuration XML is as below:
<?xml version="1.0"?>
<Config>
<Action Name="Deploy">
<CommandPath>path to navigate</CommandPath>
<PackagePath>path of Application package</PackagePath>
<ModelName>Name of model to be deployed</ModelName>
<ServiceName>Name of Service</ServiceName>
<DeploymentServer>
<Server Name = 'Server1'></Server>
<Server Name = 'Server2'></Server>
</DeploymentServer>
</Action>
<Action Name="Update">
<CommandPath>path to navigate</CommandPath>
<PackagePath>path of Application package</PackagePath>
<ModelName>Name of model to be updated</ModelName>
<ServiceName>Name of Service</ServiceName>
<DeploymentServer>
<Server Name = 'Server1'></Server>
</DeploymentServer>
</Action>
</Config>
If the user inputs Deploy, the nodes under deploy need to be considered, if the user input is update, then the update path. The Powershell code should execute for each of the items under the DeploymentServer node for each of the action item. I have tried as below, but I am not able to get the correct node information in Powershell.
Set-ExecutionPolicy RemoteSigned
function RunConfiguration()
{
$XML = Select-Xml -Path $configFile -XPath 'Action' | Select-Object -ExpandProperty Node
do {
$Answer = Read-Host -Prompt "Select required action ""$($XML.Action.Name -join '", "')"" "
} Until ($Answer -in ($XML.Action.Name))
Write-Host $XML.Action
$SelectedAnswer = $XML.Action | Where-Object {$_.Name -eq $UserOpt}
Write-Host $SelectedAnswer
$SelectedAnswer.DeploymentServer.Server | ForEach-Object {
$ServerName = $_.Name
Write-Host $ServerName
Invoke-Command -ComputerName $ServerName -ScriptBlock {
$Configuration = $args[0]
$Configuration.CommandPath
$Configuration.PackagePath
$Configuration.ModelName
$Configuration.ServiceName
} -ArgumentList $SelectedAnswer
}
}
}
}
$spAdminServiceName = "SPAdminV4"
$currentDir=(split-path $myinvocation.mycommand.path -parent)
$configFile = $currentDir
$configFile += "\DeployConfig.xml"
Execute-Commands $configFile
RunConfiguration()
Write-Host -f White "Press Enter key to exit..."
Read-Host
How to read the data? Thanks
-XPath 'Action'to-XPath '//Action'or-XPath './/Action'and see if it makes a difference.