Skip to content

Instantly share code, notes, and snippets.

@ooMia
Created July 7, 2024 15:41
Show Gist options
  • Save ooMia/d44748600e94b0366ec65398125b9c45 to your computer and use it in GitHub Desktop.
Save ooMia/d44748600e94b0366ec65398125b9c45 to your computer and use it in GitHub Desktop.
PowerShell script to get GitHub avatar
# PowerShell script to get GitHub avatar
# Prompt the user for the GitHub username
$username = Read-Host "Enter GitHub username"
# Make a GET request to the GitHub API to fetch the user's avatar URL
$response = Invoke-RestMethod -Uri "https://api.github.com/users/$username"
$id = $response.id
$avatar_url = $response.avatar_url
# Ask the user if they want to download the avatar or just get the URL
$action = Read-Host @"
(1) Download the avatar
(2) Just get the URL
>>
"@
if ($action -eq "1") {
# Download the avatar image using the fetched URL
Invoke-WebRequest -Uri $avatar_url -OutFile "$id.jpg"
# Display a success message
Write-Host "Avatar downloaded successfully!"
} elseif ($action -eq "2") {
# Display the avatar URL
Write-Host "Avatar URL: $avatar_url"
} else {
Write-Host "Invalid option selected."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment