makeConfig.ps1
param(
[switch]$Syst,
[switch]$Acct,
[switch]$Prod,
[string]$Type = "",
[switch]$Help,
[switch]$Verbose
)
$configFile = "makeconfig.xml"
$xmlConfig = $null
FUNCTION readConfig()
{
if( !(Test-Path $configFile ))
{
Write-Host ("File " + $configFile + " is not found!")
return
}
Try
{
$xmlConfig = [xml](get-content $configFile)
}
Catch
{
Write-Host ("Error by reading file " + $configFile )
if($Verbose.IsPresent)
{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Write-Host $ErrorMessage
Write-Host $FailedItem
}
return
}
return $xmlConfig
}
Function help()
{
Write-Host "NAME"
Write-Host " makeConfig"
Write-Host
Write-Host "SYNTAX"
Write-Host " makeConfig" [-Help]"
Write-Host " makeConfig" [-Verbose] [-Syst] [-ACCT] [-PROD] [-Type [type]]"
Write-Host
Write-Host "SWITCH"
Write-Host " -Help = help"
Write-Host " -Syst = select target Syst"
Write-Host " -Acct = select target Acct"
Write-Host " -Prod = select target Prod"
Write-Host " -Verbose = display output"
Write-Host
Write-Host "PARAMETER"
Write-Host " -Type <type> = sub select only a type"
Write-Host
Write-Host "MAKECONFIG.XML example"
Write-Host "<configs> "
Write-Host " <part> "
Write-Host " <type>a</type> "
Write-Host " <config> "
Write-Host " <target>syst</target> "
Write-Host " <command>a-syst</command> "
Write-Host " </config> "
Write-Host " <config> "
Write-Host " <target>acct</target> "
Write-Host " <command>a-acct</command> "
Write-Host " </config> "
Write-Host " <config> "
Write-Host " <target>prod</target> "
Write-Host " <command>a-prod</command> "
Write-Host " </config> "
Write-Host " </part> "
Write-Host " <part> "
Write-Host " <type>b</type> "
Write-Host " <config> "
Write-Host " <target>syst</target> "
Write-Host " <command>b-syst</command> "
Write-Host " </config> "
Write-Host " <config> "
Write-Host " <target>acct</target> "
Write-Host " <command>b-acct</command> "
Write-Host " </config> "
Write-Host " <config> "
Write-Host " <target>prod</target> "
Write-Host " <command>b-prod</command> "
Write-Host " </config> "
Write-Host " </part> "
Write-Host " <part> "
Write-Host " <type>c</type> "
Write-Host " <config> "
Write-Host " <target>syst</target> "
Write-Host " <command>c-syst</command> "
Write-Host " </config> "
Write-Host " <config> "
Write-Host " <target>acct</target> "
Write-Host " <command>c-acct</command> "
Write-Host " </config> "
Write-Host " <config> "
Write-Host " <target>prod</target> "
Write-Host " <command>c-prod</command> "
Write-Host " </config> "
Write-Host " </part> "
Write-Host "</configs> "
Write-Host "AUTHEUR"
Write-Host " Pascal"
Write-Host
Write-Host "VERSION"
Write-Host " 1"
Write-Host
Write-Host "DATE 29-5-2014"
}
Function go()
{
param([Parameter(Mandatory=$true)][string]$Target,
[Parameter(Mandatory=$true)][xml]$XmlConfig)
if($Type -ne "")
{
$outputType = $XmlConfig.configs.part | where { $_.type -eq $Type}
$output = $outputType.config | where { $_.target -eq $Target }
}
else
{
$output = $XmlConfig.configs.part.config | where { $_.target -eq $Target }
}
if($output -eq $null)
{
return
}
if($Type -ne "")
{
$outputFile = ('config-' + $Type+'-' +$Target + '.cmd')
}
else
{
$outputFile = ('config-' + $Target + '.cmd')
}
$date = Get-Date
("REM " + $date) > $outputFile
"" >> $outputFile
$output.command >> $outputFile
if($Verbose.IsPresent)
{
Write-Host
Get-Content $outputFile
}
return
}
if($Help.IsPresent)
{
help
return $null
}
# read the makeconfig config file
$xmlConfig = readConfig
if($Syst.IsPresent)
{
go 'syst' $xmlConfig
}
if($Acct.IsPresent)
{
go 'acct' $xmlConfig
}
if($Prod.IsPresent)
{
go 'prod' $xmlConfig
}