Skip to content

Instantly share code, notes, and snippets.

@jazzbanzai
Created April 6, 2023 17:52
Show Gist options
  • Save jazzbanzai/f5148e5351db62d3f0bf271a495eec3c to your computer and use it in GitHub Desktop.
Save jazzbanzai/f5148e5351db62d3f0bf271a495eec3c to your computer and use it in GitHub Desktop.
PowerShell code to check UK NS&I Premium Bonds wins based on Holders Number
# PowerShell code to check UK NS&I Premium Bonds wins based on Holders Number
# URL: https://www.nsandi.com/prize-checker
# Holders Number -- Replace with your holders number (not the same as your account number)
# This number has 10 or 9 digits, or 8 digits followed by a letter. You can find your holder’s number
# by logging in to our online service and checking your Premium Bonds account page.
$BondHoldersNumber = '83674004A' #random valid number
############
# Const
############
$Headers = @{
# Origin = "https://www.nsandi.com"
# Referer = "https://www.nsandi.com/prize-checker"
ContentType = "application/x-www-form-urlencoded"
}
$URI = "https://www.nsandi.com/premium-bonds-have-i-won-ajax"
############
# This month
############
$Body = "field_premium_bond_period=this_month&field_premium_bond_number=$BondHoldersNumber"
$Results = Invoke-WebRequest -UseBasicParsing -Uri $URI -Method "POST" -Body $Body -Headers $Headers
if ($Results.StatusCode -ne 200) {
Write-Error "Failed to retrieve results. Status code: $($Results.StatusCode)"
} else {
$Json = $Results.Content | ConvertFrom-Json
Write-Host $Json.tagline -ForegroundColor Green
$Json
}
############
# 6 months
############
$Body = "field_premium_bond_period=last_six_month&field_premium_bond_number=$BondHoldersNumber"
$Results = Invoke-WebRequest -UseBasicParsing -Uri $URI -Method "POST" -Body $Body -Headers $Headers
if ($Results.StatusCode -ne 200) {
Write-Error "Failed to retrieve results. Status code: $($Results.StatusCode)"
} else {
$Json = $Results.Content | ConvertFrom-Json
Write-Host $Json.tagline -ForegroundColor Green
$Json.history
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment