-
Notifications
You must be signed in to change notification settings - Fork 1
/
rebuild_whdload_index.ps1
39 lines (28 loc) · 1.35 KB
/
rebuild_whdload_index.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
$outputPath = "whdload_installs_index"
function RebuildWhdloadIndexFromFiles($outputPath, $whdloadArchiveFiles)
{
$whdloadIndexPath = [System.IO.Path]::Combine($outputPath, "whdload_index_rebuild.csv")
if(test-path -path $whdloadIndexPath)
{
Remove-Item $whdloadIndexPath
}
# add header to index
Add-Content $whdloadIndexPath "Whdload Archive File;Whdload Slave File;Whdload Name"
# get whdload text files from temp path
$whdloadTextFiles = Get-ChildItem -recurse -filter *.txt -Path $outputPath
# add no slaves to index, if no slaves exist in temp path
if (!$whdloadTextFiles)
{
Add-Content $whdloadIndexPath "$($whdloadArchiveFile.Name);ERROR - NO SLAVES"
}
ForEach ($whdloadSlaveFile in $whdloadSlaveFiles)
{
$whdloadSlaveTextFile = [System.IO.Path]::Combine($outputPath, "$($whdloadArchiveFile.Name)_$($whdloadSlaveFile.Name).txt")
# read whdload slave information and write to text
& $readWhdloadSlavePath -path $whdloadSlaveFile.FullName | Out-File $whdloadSlaveTextFile
# get whdload name
$name = Get-Content $whdloadSlaveTextFile | Select-String -Pattern "Name\s+=\s+'([^']+)" -AllMatches | % { $_.Matches } | % { $_.Groups[1].Value } | Select-Object -first 1
# add whdload details to index
Add-Content $whdloadIndexPath "$($whdloadArchiveFile.Name);$($whdloadSlaveFile.Name);$name"
}
}