-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinux_config_to_ob.ps1
32 lines (30 loc) · 997 Bytes
/
linux_config_to_ob.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
#ADVANCED FUNCTIONS MUAHAHAH
[CmdletBinding(SupportsShouldProcess=$true)]
#prepmpt output type
[OutputType("PSObject")]
param(
[parameter(Mandatory=$true, Position=1)]
$File
)
Begin{
$ErrorActionPreference = "Stop"
$ConfigObj = New-Object -TypeName PSObject
$file_input = Get-Content $File | Where-Object {!($_ -match "^#")}
foreach($line in $file_input){
if($line.Length -gt 1){
$key, $value = $line.Split()
#this will only work if the same keys are right under each other
if($ConfigObj.$key -and $ConfigObj.$key.GetType() -ne [System.Array]){
$ConfigObj.$key = @($ConfigObj.$key)
$ConfigObj.$key += $value
}
elseif($ConfigObj.$key){
$ConfigObj.$key += $value
}
else{
Add-Member -InputObject $ConfigObj -Name $key -Value $value -MemberType NoteProperty
}
}
}
return $ConfigObj
}