Thor Logo dbatools

Get-DbaRandomizedDataset

View Source
Sander Stad (@sqlstad, sqlstad.nl)
Windows, Linux, macOS

Synopsis

Generates random test data using predefined templates for development and testing scenarios

Description

Generates random test datasets using JSON templates that define column names and data types. This function creates realistic sample data for database development, testing, and training environments without exposing production data. Templates can specify SQL Server data types (varchar, int, datetime) or semantic data types (Name.FirstName, Address.City, Person.DateOfBirth) for more realistic datasets. Built-in templates include PersonalData with common PII fields, and you can create custom templates for specific business scenarios.

Syntax

Get-DbaRandomizedDataset
    [[-Template] <String[]>]
    [[-TemplateFile] <String[]>]
    [[-Rows] <Int32>]
    [[-Locale] <String>]
    [[-InputObject] <Object[]>]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1

PS > Get-DbaRandomizedDataset -Template Personaldata
Generate a data set based on the default template PersonalData.

Example: 2

PS > Get-DbaRandomizedDataset -Template Personaldata -Rows 10
Generate a data set based on the default template PersonalData with 10 rows

Example: 3

PS > Get-DbaRandomizedDataset -TemplateFile C:\Dataset\FinancialData.json
Generates data set based on a template file in another directory

Example: 4

PS > Get-DbaRandomizedDataset -Template Personaldata, FinancialData
Generates multiple data sets

Example: 5

PS > Get-DbaRandomizedDatasetTemplate -Template PersonalData | Get-DbaRandomizedDataset
Pipe the templates from Get-DbaRandomizedDatasetTemplate to Get-DbaRandomizedDataset and generate the data set

Optional Parameters

-Template

Specifies the name of one or more built-in templates to use for data generation.
Use this when you want to generate data using predefined column structures like PersonalData which includes names, addresses, and birthdates.
The function searches through default templates in the module’s bin\randomizer\templates directory to find matching names.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-TemplateFile

Specifies the full path to one or more custom JSON template files that define column structures and data types.
Use this when you need to generate data based on your own custom templates rather than the built-in ones.
Template files must be valid JSON with a Columns array defining Name, Type, and SubType properties for each column.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-Rows

Specifies how many rows of test data to generate for each template.
Use this to control the size of your test dataset based on your development or testing needs.
Defaults to 100 rows if not specified.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value100
-Locale

Specifies the locale for generating culture-specific data like names, addresses, and phone numbers.
Use this when you need test data that matches a specific geographic region or language for realistic testing scenarios.
Defaults to ’en’ (English) if not specified.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Valueen
-InputObject

Accepts template objects piped from Get-DbaRandomizedDatasetTemplate.
Use this in pipeline scenarios where you first retrieve templates and then generate data from them.
Each input object should contain template information including the FullName path to the JSON template file.

PropertyValue
Alias
RequiredFalse
Pipelinetrue (ByValue)
Default Value
-EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with “sea of red” exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this “nice by default” feature off and enables you to catch exceptions with your own try/catch.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default ValueFalse

Outputs

PSCustomObject

Returns one PSCustomObject per generated row. The properties of each object are dynamically defined by the columns array in the template JSON file.

Properties depend on the template used:

  • Each property name corresponds to a column.Name value from the template file
  • Each property value is generated by Get-DbaRandomizedValue based on the column’s Type and SubType
  • Property data types vary based on the semantic type specified (string, int, datetime, guid, etc.)

Example with PersonalData template (typical properties):

  • FirstName: Generated first name (string)
  • LastName: Generated last name (string)
  • Email: Generated email address (string)
  • PhoneNumber: Generated phone number (string)
  • DateOfBirth: Generated birth date (datetime)
  • Address: Generated street address (string)
  • City: Generated city name (string)
  • ZipCode: Generated postal code (string)
  • Country: Generated country name (string) The actual properties returned depend on the template specified via -Template or -TemplateFile parameter. Custom templates can define any column names and data types needed for your test data scenarios.