Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
function Get-RandomUser {
Generate random user data.
This function uses the free API for generating random user data from
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 = "$($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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment