-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConvertTo-WebArchitect.psm1
93 lines (72 loc) · 2.75 KB
/
ConvertTo-WebArchitect.psm1
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
<#
.Synopsis
Convert Fujitsu XML to CSV format
.Description
The `ConvertTo-WebArchitect` cmdlet import transaction Fujitsu XML into a series of character-separated value (CSV) strings.
.Parameter InputObject
Specifies the objects that are converted to CSV strings. Enter a variable that contains the objects or type a command or expression that gets the objects.
.Parameter OutputObject
Specifies the output filename of CSV.
.Parameter Token
File path of WebArchitect master database.
.Example
ConvertTo-WebArchitect -inFile input.xml
.LINK
Project homepage: https://github.com/scout249/fujitsu-xml2csv
#>
#Installation
#Install-Module -Name JoinModule
function Convert-WebArchitect {
[CmdletBinding()]
Param(
[string]$inFile,
[string]$outFile,
[switch]$master
)
$path = [Environment]::GetFolderPath('ApplicationData')
$Colors = @{
ForegroundColor = "White"
BackgroundColor = "Red"
}
if ($master -ne $true) {
if ((Test-Path "$path\WebArchitectMaster.txt") -ne $true) {
Write-Host "Please run 'Convert-WebArchitect -master' to provide master database (Missing)" @colors
}
elseif ($inFile -eq '') {
Write-Host "Please run 'Convert-WebArchitect -inFile <<YOUR XML FILE>>' to convert to CSV (Missing)" @colors
}
else {
## Define variables
$masterFile = gc "$path\WebArchitectMaster.txt"
#Define Variable
#$baseDir = "C:\XML2CSV"
#$inFile = "Multi Configuration.xml"
$outFile = -join($inFile, ".csv")
$temp = "temp.txt"
#Remove <Components> Tag
(gc $inFile -raw) | % {
$_ -replace '</Components>\s*</Component>' `
-replace '<Components>', '</Component>'
} | sc $temp
#Convert XML to CSV
[xml]$xmlin = Get-Content $temp
$xmlin.Order.Systems.Component | select `
@{N="Product Name"; E={$_.name}},
@{N="Part Number"; E={$_.SachNr}},
@{N="Quantity"; E={$_.Count}},
@{N="Unit Price"; E={"0"}} | epcsv $outFile -NoTypeInformation
#Merge Tables
$importMaster = ipcsv $masterFile |
Select "Part Number", "CP Figure Number"
ipcsv $outFile |
InnerJoin $importMaster -On "Part Number" |
Select "Product Name", "Part Number", "CP Figure Number", "Quantity", "Unit Price" |
epcsv temp.txt -NoTypeInformation
#Append to CSV file
ac $temp ",,,,Total Price`n,,,,0"
del $outFile
rni $temp $outFile
}
}
}
Export-ModuleMember -Function ConvertTo-WebArchitect