-
Notifications
You must be signed in to change notification settings - Fork 0
/
Split-File.ps1
39 lines (31 loc) · 1 KB
/
Split-File.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
function Split-File {
<#
.SYNOPSIS
Takes an formats or types file and splits it into separate files.
.DESCRIPTION
The input file must be a ps1xml file of formats. A file will be created
from the Name node.
.PARAMETER InputFile
The ps1xml file to process.
.EXAMPLE
PS C:\> Split-File -InputFile .\Source\formats\builds.format.ps1xml
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $True)]
[string]
$inputFile
)
[xml]$xml = Get-Content $inputFile
foreach ($view in $xml.Configuration.ViewDefinitions.View) {
$finalXml = '<?xml version="1.0" encoding="utf-8" ?><Configuration><ViewDefinitions>'
$finalXml += $view.OuterXml
$finalXml += '</ViewDefinitions></Configuration>'
$output = Join-Path . "$($view.Name).ps1xml"
# This makes sure the file is there and empty.
# If the file already exisit it will be overwritten.
$null = New-Item -ItemType file -Path $output -Force
Write-Verbose $output
$finalXml | Add-Content $output
}
}