mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-07-20 21:10:20 +08:00
37 lines
800 B
PowerShell
37 lines
800 B
PowerShell
<#
|
|
.SYNOPSIS
|
|
Serializes a configuration hashtable to a UTF-8 JSON file.
|
|
|
|
.PARAMETER Config
|
|
The configuration data to serialize.
|
|
|
|
.PARAMETER FilePath
|
|
The destination file path.
|
|
|
|
.PARAMETER MaxDepth
|
|
The maximum object depth passed to ConvertTo-Json.
|
|
|
|
.OUTPUTS
|
|
System.Boolean. $true when the file is written; otherwise $false.
|
|
#>
|
|
function Save-ToFile {
|
|
param (
|
|
[Parameter(Mandatory=$true)]
|
|
[hashtable]$Config,
|
|
|
|
[Parameter(Mandatory=$true)]
|
|
[string]$FilePath,
|
|
|
|
[Parameter(Mandatory=$false)]
|
|
[int]$MaxDepth = 10
|
|
)
|
|
|
|
try {
|
|
$Config | ConvertTo-Json -Depth $MaxDepth | Set-Content -Path $FilePath -Encoding UTF8
|
|
return $true
|
|
}
|
|
catch {
|
|
return $false
|
|
}
|
|
}
|