-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAdhcConfigGen.ps1
205 lines (156 loc) · 6.09 KB
/
AdhcConfigGen.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# Mass update of GIT config files
$Version = " -- Version: 4.1.1"
# COMMON coding
CLS
$InformationPreference = "Continue"
$WarningPreference = "Continue"
$ErrorActionPreference = "Stop"
$Node = " -- Node: " + $env:COMPUTERNAME
$d = Get-Date
$Datum = " -- Date: " + $d.ToString("dd-MM-yyyy")
$Tijd = " -- Time: " + $d.ToString("HH:mm:ss")
$myname = $MyInvocation.MyCommand.Name
$FullScriptName = $MyInvocation.MyCommand.Definition
$mypath = $FullScriptName.Replace($MyName, "")
$Scriptmsg = "*** STARTED *** " + $mypath + " -- PowerShell script " + $MyName + $Version + $Datum + $Tijd +$Node
Write-Information $Scriptmsg
$LocalInitVar = $mypath + "InitVar.PS1"
$InitObj = & "$LocalInitVar" "MSG"
if ($Initobj.Abend) {
# Write-Warning "YES"
throw "INIT script $LocalInitVar Failed"
}
# END OF COMMON CODING
function Set_Value ([string]$istr) {
if ($istr.Length -gt 6) {
if ($istr.substring(0,6) -eq '$ADHC_'){
$istr = Invoke-Expression($istr);
}
}
return $istr
}
$masterxml = [xml](Get-Content $ADHC_MasterXml)
$factorylist = $masterxml.ADHCmaster.ChildNodes
$version = $masterxml.ADHCmaster.Version
write-host " "
Write-Host "Master XML version = $version"
write-host " "
foreach ($factory in $factorylist) {
$factroot = $factory.Root
$factroot = Set_Value($factroot)
$subdevdir = $factory.SubRoot
Write-Host "Factory = $subdevdir"
$ADHCinfolist = $factory.Childnodes
foreach ($infoentry in $ADHCinfolist) {
[xml]$xmldoc = New-Object System.Xml.XmlDocument
$decl = $xmldoc.CreateXmlDeclaration('1.0','UTF-8',$null)
[void]$xmldoc.AppendChild($decl)
$nodes = $infoentry.Nodes
$nodes = Set_Value($nodes)
write-host "Target nodes = $nodes"
$adhcinfo = $xmldoc.CreateElement("ADHCinfo")
$adhcinfo.SetAttribute("Version",$version)
$adhcinfo.SetAttribute("Nodes", $nodes)
$adhcinfo.SetAttribute("Factory", $factroot)
$adhcinfo.SetAttribute("SubRoot", $subdevdir)
$liblist = $infoentry.CHildNodes
Write-Host "Libnames: "
foreach ($lib in $liblist) {
$Naam = $lib.Name Write-Host "Naam = $Naam"
$root = $lib.Root
$root = Set_Value($root)
Write-Host "Root = $root"
$subroot = $lib.SubRoot
If ($subroot -eq "*") {
$subroot = $subdevdir
}
Write-Host "Subroot = $subroot"
$Process = $lib.Process
Write-Host "Process = $Process"
$Delay = $lib.Delay
Write-Host "Delay = $Delay"
$ModulesList = $lib.ChildNodes
$cnt = $lib.ChildNodes.Count
Write-Host "Aantal MODULES entries: $cnt"
$comment = $false
switch ($Naam.ToUpper().Trim()) {
"STAGELIB" {
$thischild = $xmldoc.CreateElement("StageLib")
$stageroot = $subroot
}
"TARGET" {
$thischild = $xmldoc.CreateElement("Target")
}
"DSL" {
$thischild = $xmldoc.CreateElement("DSL")
}
"#COMMENT" {
$txt = $lib.InnerText
$thischild = $xmldoc.CreateComment($txt)
$comment = $true
}
default {
Write-Error "$Naam niet herkend"
Exit 16
}
}
if (!$comment) {
$thischild.SetAttribute("Root",$root)
$thischild.SetAttribute("SubRoot", $subroot)
foreach ($modentry in $ModulesList) {
$m = $xmldoc.CreateElement("Modules")
$p = $modentry.Process
if ($p) {
if ($p -eq "*") {
$mprocess = $Process
}
else {
$mprocess = $p
}
}
else {
$mprocess = $Process
}
$m.SetAttribute("Process",$mprocess)
$dly = $modentry.Delay
if ($dly) {
$mdelay= $dly
}
else {
$mdelay = $Delay
}
$m.SetAttribute("Delay",$mdelay)
$Include = $modentry.Include
if (!$Include) {
$Include = "*ALL*"
}
$Exclude = $modentry.Exclude
if (!$Exclude) {
$Exclude = "*None*"
}
$i = $xmldoc.CreateElement("Include")
$i.InnerText = $Include
$e = $xmldoc.CreateElement("Exclude")
$e.InnerText = $Exclude
[void]$m.AppendChild($i)
[void]$m.AppendChild($e)
[void]$thischild.AppendChild($m)
}
}
[void]$adhcinfo.AppendChild($thischild)
}
[void]$xmldoc.AppendChild($adhcinfo)
# Write xml to config dataset
$outdir = $ADHC_StagingDir + $stageroot
New-Item -ItemType Directory -Force -Path $outdir | Out-Null
$fullname = $outdir + $ADHC_configfile
$xmlDoc.Save($fullName)
write-host " "
}
}
$d = Get-Date
$Datum = " -- Date: " + $d.ToString("dd-MM-yyyy")
$Tijd = " -- Time: " + $d.ToString("HH:mm:ss")
$Scriptmsg = "*** ENDED ***** " + $mypath + " -- PowerShell script " + $MyName + $Version + $Datum + $Tijd +$Node
Write-Information $Scriptmsg