Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Get-MinecraftSkin.ps1 - jorgtheelder@outlook.com 2018
- param (
- [Parameter(Mandatory)]
- [string]$username
- )
- $ErrorActionPreference = 'Stop';
- $uri1 = 'https://api.mojang.com/users/profiles/minecraft/';
- $uri2 = 'https://sessionserver.mojang.com/session/minecraft/profile/';
- $rest1 = $uri1 + $username;
- 'Looking up UUID for: ' + $username;
- $result = Invoke-RestMethod $rest1;
- $name = $result.name;
- $uuid = $result.id;
- if($name -and $uuid -and $uuid -match '^[0-9a-z]+$') {
- 'Name: ' + $name;
- 'UUID: ' + $uuid;
- $file = $name + '.jpg';
- $rest2 = $uri2 + $uuid;
- 'Getting textures struct';
- $result2 = Invoke-RestMethod $rest2;
- if($result2.properties.name -eq 'textures') {
- $info = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($result2.properties.value)) | ConvertFrom-Json;
- $skinUri = $info.textures.skin.url;
- if(-not($skinUri -match 'textures.minecraft.net')) {
- throw 'Textures struct did not contain a valid SKIN uri';
- }
- 'Getting skin and saving to file: ' + $file;
- Invoke-WebRequest -Uri $skinUri -UseBasicParsing -OutFile $file;
- 'Done';
- } else {
- throw 'Unable to retreive textures';
- }
- } else {
- throw 'Failed to retreive user info for: ' + $username;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement