5/18/2016 - 4:53 AM


function Get-RandomUser {
            Generate random user data.
            This function uses the free API for generating random user data from https://randomuser.me/
            Get-RandomUser 10
            Get-RandomUser -Amount 25 -Nationality us,gb -Format csv -ExludeFields picture
            Author: Øyvind Kallstad
            Date: 08.04.2016
            Version: 2.0
    param (
        [Parameter(Position = 0)]
        [int] $Amount,

        [string] $Gender,

        # Pictures won't be affected by this, but data such as location, cell/home phone, id, etc. will be more appropriate.
        [string[]] $Nationality,

        # Seeds allow you to always generate the same set of users.
        [int] $Seed,

        [string] $Format = 'json',

        # Fields to include in the results.
        [string[]] $IncludeFields,

        # Fields to exclude from the the results.
        [string[]] $ExcludeFields
    $rootUrl = "http://api.randomuser.me/?format=$($Format)"
    $htParamAlias = (Get-Command Get-RandomUser).Parameters.Values | Where-Object Aliases | 
        Select-Object Name, Aliases | Group-Object Name -AsHashTable -AsString
    $PSBoundParameters.GetEnumerator() | foreach {
        $value = $_.Value -join ','
        $key = $_.Key
        if ($htParamAlias.ContainsKey($key)){
            $key = $htParamAlias.$Key.Aliases.ToLower()
        $rootUrl += "&$key=$value"
    Invoke-RestMethod -Uri $rootUrl