Created
July 2, 2024 17:07
-
-
Save piotrkochan/d0658f22f9d419046c02251b16bde184 to your computer and use it in GitHub Desktop.
Chocolatey - sync packages with github gist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Chocolatey Package Export Script | |
# Get the list of installed Chocolatey packages | |
$chocoList = choco list --local-only --limit-output | |
$packageList = $chocoList -join "`n" | |
# GitHub Personal Access Token (replace with your own) | |
# https://github.com/settings/tokens?type=beta | |
$token = "xxxxx" | |
# GitHub Gist ID (replace with your own) | |
$gistId = "YOUR_GIST_ID" | |
# Gist API URL | |
$apiUrl = "https://api.github.com/gists/$gistId" | |
# Create the request body | |
$body = @{ | |
files = @{ | |
"choco-packages.txt" = @{ | |
content = $packageList | |
} | |
} | |
} | ConvertTo-Json | |
# Send the update request to GitHub | |
Invoke-RestMethod -Uri $apiUrl -Method Patch -Headers @{ | |
Authorization = "token $token" | |
"Content-Type" = "application/json" | |
} -Body $body |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment