Advertisement
JorgTheElder

Get-MinecraftSkin.ps1

Apr 27th, 2018
3,768
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Get-MinecraftSkin.ps1 - jorgtheelder@outlook.com 2018
  2.  
  3. param (
  4.  
  5.   [Parameter(Mandatory)]
  6.   [string]$username
  7.  
  8. )
  9.  
  10. $ErrorActionPreference = 'Stop';
  11.  
  12. $uri1 = 'https://api.mojang.com/users/profiles/minecraft/';
  13. $uri2 = 'https://sessionserver.mojang.com/session/minecraft/profile/';
  14.  
  15. $rest1 = $uri1 + $username;
  16.  
  17. 'Looking up UUID for: ' + $username;
  18.  
  19. $result = Invoke-RestMethod $rest1;
  20.  
  21. $name = $result.name;
  22. $uuid = $result.id;
  23.  
  24. if($name -and $uuid -and $uuid -match '^[0-9a-z]+$') {
  25.  
  26.   'Name: ' + $name;
  27.   'UUID: ' + $uuid;
  28.   $file = $name + '.jpg';
  29.  
  30.   $rest2 = $uri2 + $uuid;
  31.  
  32.   'Getting textures struct';
  33.  
  34.   $result2 = Invoke-RestMethod $rest2;
  35.  
  36.   if($result2.properties.name -eq 'textures') {
  37.  
  38.     $info = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($result2.properties.value)) | ConvertFrom-Json;
  39.  
  40.     $skinUri = $info.textures.skin.url;
  41.  
  42.     if(-not($skinUri -match 'textures.minecraft.net')) {
  43.  
  44.       throw 'Textures struct did not contain a valid SKIN uri';
  45.  
  46.     }
  47.  
  48.     'Getting skin and saving to file: ' + $file;
  49.  
  50.     Invoke-WebRequest -Uri $skinUri -UseBasicParsing -OutFile $file;
  51.  
  52.     'Done';
  53.  
  54.   } else {
  55.    
  56.     throw 'Unable to retreive textures';
  57.  
  58.   }
  59.  
  60.  
  61. } else {
  62.  
  63.   throw 'Failed to retreive user info for: ' + $username;
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement