Skip to content

Instantly share code, notes, and snippets.

@piotrkochan
Created July 2, 2024 17:07
Show Gist options
  • Save piotrkochan/d0658f22f9d419046c02251b16bde184 to your computer and use it in GitHub Desktop.
Save piotrkochan/d0658f22f9d419046c02251b16bde184 to your computer and use it in GitHub Desktop.
Chocolatey - sync packages with github gist
# 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