Skip to content

Instantly share code, notes, and snippets.

@DailenG
Last active May 15, 2023 19:52
Show Gist options
  • Save DailenG/40db87032199c579a08c211f529f264a to your computer and use it in GitHub Desktop.
Save DailenG/40db87032199c579a08c211f529f264a to your computer and use it in GitHub Desktop.
Converts WingetUI Config to JSON String, Saves in config directory as JSON string in .json file
$directory = "$ENV:USERPROFILE\.wingetui"
# Get a list of text files in the directory (excluding files with extensions)
$files = Get-ChildItem -Path $directory -File | Where-Object { $_.Name -notmatch '\.' }
# Create an empty hashtable to store the key-value pairs
$data = @{}
# Iterate through each file and add its contents to the hashtable
foreach ($file in $files) {
$key = $file.BaseName
$value = Get-Content $file.FullName -Raw
if ([string]::IsNullOrEmpty($value)) {
$data[$key] = $true
} else {
$data[$key] = $value
}
}
# Create a custom object with the Config property containing the data hashtable
$result = [PSCustomObject]@{
Config = $data
}
# Convert the custom object to a JSON string
$jsonString = $result | ConvertTo-Json
# Save the JSON string to respective files
$jsonString | Set-Content -Path "$directory\WingetUIConfig.json"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment