Public/API/Get-SteamFriendList.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
function Get-SteamFriendList {
    <#
    .SYNOPSIS
    Returns the friend list of any Steam user.

    .DESCRIPTION
    Returns the friend list of any Steam user, provided their Steam Community
    profile visibility is set to "Public".

    .PARAMETER SteamID64
    64 bit Steam ID to return friend list for.

    .PARAMETER Relationship
    Relationship filter. Possibles values: all, friend.

    .PARAMETER OutputFormat
    Format of the output. Options are json (default), xml or vdf.

    .EXAMPLE
    Get-SteamFriendList -SteamID64 76561197960435530

    Outputs the user's friends list, as an array of friends.

    .EXAMPLE
    Get-SteamFriendList -SteamID64 76561197960435530 | ConvertFrom-Json

    Outputs the user's friends list, as an array of friends and converts it from
    Json to PSCustomObjects.

    .INPUTS
    int64

    .OUTPUTS
    Returns a string that is either formatted as json, xml or vdf.

    The user's friends list, as an array of friends. Nothing will be returned
    if the profile is private.

    In the array, the following three properties are returned:
    - steamid: 64 bit Steam ID of the friend.
    - relationship: Relationship qualifier.
    - friend_since: Unix timestamp of the time when the relationship was created.

    .NOTES
    Author: Frederik Hjorslev Nylander

    .LINK
    https://hjorslev.github.io/SteamPS/Get-SteamFriendList.html
    #>


    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true,
            HelpMessage = '64 bit Steam ID to return friend list for.',
            ValueFromPipelineByPropertyName = $true)]
        [int64]$SteamID64,

        [Parameter(Mandatory = $false,
            HelpMessage = 'Relationship filter. Possibles values: all, friend.')]
        [ValidateSet('all', 'friend')]
        [string]$Relationship,

        [Parameter(Mandatory = $false,
            HelpMessage = 'Format of the output. Options are json (default), xml or vdf.')]
        [ValidateSet('json', 'xml', 'vdf')]
        [string]$OutputFormat = 'json'
    )

    begin {
        Write-Verbose -Message "[BEGIN ] Starting: $($MyInvocation.MyCommand)"
    }

    process {
        $Request = Invoke-WebRequest -Uri "https://api.steampowered.com/ISteamUser/GetFriendList/v1/?key=$(Get-SteamAPIKey)&steamid=$SteamID64&relationship=friend&format=$OutputFormat" -UseBasicParsing

        Write-Output -InputObject $Request.Content
    } # Process

    end {
        Write-Verbose -Message "[END ] Ending: $($MyInvocation.MyCommand)"
    }
} # Cmdlet