Update module version to 1.0.1 and add new functions for exporting and deploying DSC configuration data
This commit is contained in:
32
Public/Export-PowerShellDataFile.ps1
Normal file
32
Public/Export-PowerShellDataFile.ps1
Normal file
@@ -0,0 +1,32 @@
|
||||
function Export-PowerShellDataFile {
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
|
||||
[System.Collections.IDictionary]
|
||||
$InputObject,
|
||||
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]
|
||||
$Path,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[switch]
|
||||
$Force
|
||||
)
|
||||
|
||||
process {
|
||||
$ResolvedPath = Repair-ConfigurationDataPathEncoding -Path $Path
|
||||
|
||||
if((Test-Path -LiteralPath $ResolvedPath -PathType Leaf) -and (-not $Force)){
|
||||
throw "File [$ResolvedPath] already exists. Use -Force to overwrite it."
|
||||
}
|
||||
|
||||
$Parent = Split-Path -Path $ResolvedPath -Parent
|
||||
if(-not [string]::IsNullOrWhiteSpace($Parent) -and -not (Test-Path -LiteralPath $Parent)){
|
||||
New-Item -Path $Parent -ItemType Directory -Force | Out-Null
|
||||
}
|
||||
|
||||
$Text = ConvertTo-PowerShellDataFileText -InputObject $InputObject
|
||||
Set-Content -LiteralPath $ResolvedPath -Value $Text -Encoding UTF8
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user