-
Notifications
You must be signed in to change notification settings - Fork 14
/
Export-PSData.ps1
46 lines (40 loc) · 2.39 KB
/
Export-PSData.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
function Export-PSData
{
<#
.Synopsis
Exports property bags into a data file
.Description
Exports property bags and the first level of any other object into a ps data file (.psd1)
.Link
Import-PSData
.Example
Get-Web -Url http://www.youtube.com/watch?v=xPRC3EDR_GU -AsMicrodata -ItemType http://schema.org/VideoObject |
Export-PSData .\PipeworksQuickstart.video.psd1
#>
[OutputType([IO.FileInfo])]
param(
# The data that will be exported
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[PSObject[]]
$InputObject,
# The path to the data file
[Parameter(Mandatory=$true,Position=0)]
[string]
$DataFile
)
begin {
$AllObjects = New-Object Collections.ArrayList
}
process {
$null = $AllObjects.AddRange($InputObject)
}
end {
#region Convert to Hashtables and export
$text = $AllObjects |
Write-PowerShellHashtable
$text |
Set-Content -Path $DataFile
Get-Item -Path $DataFile
#endregion Convert to Hashtables and export
}
}