29 lines
803 B
PowerShell
29 lines
803 B
PowerShell
function Export-PowerShellDataFile {
|
|
[CmdletBinding()]
|
|
Param(
|
|
[Parameter(Mandatory=$true)]
|
|
[System.Collections.IDictionary]
|
|
$InputObject,
|
|
|
|
[Parameter(Mandatory=$true)]
|
|
[string]
|
|
$Path,
|
|
|
|
[Parameter(Mandatory=$false)]
|
|
[switch]
|
|
$Force
|
|
)
|
|
|
|
if((Test-Path -Path $Path -PathType Leaf) -and (-not $Force)){
|
|
throw "File [$Path] already exists. Use -Force to overwrite it."
|
|
}
|
|
|
|
$Parent = Split-Path -Path $Path -Parent
|
|
if(-not [string]::IsNullOrWhiteSpace($Parent) -and -not (Test-Path -Path $Parent)){
|
|
New-Item -Path $Parent -ItemType Directory -Force | Out-Null
|
|
}
|
|
|
|
$Text = ConvertTo-PowerShellDataFileText -InputObject $InputObject
|
|
Set-Content -Path $Path -Value $Text -Encoding UTF8
|
|
}
|