---
title: Generate Batch Log Events with PowerShell 7 | Nodinite Testing Guide
description: PowerShell 7 script to generate batches of Nodinite JSON Log Events for demos and load testing. Create hundreds of realistic order events with randomized data and base64-encoded payloads.
---

# FAQ — Generate Batch Log Events (PowerShell 7)

This FAQ shows how to generate batches of :Nodinite: JSON [Log Events][Log Event] for demos, load testing, and training environments using [PowerShell 7][].

What you'll find on this page:

* **Batch generation script** - Create hundreds of realistic order events for testing
* **Ready-to-use examples** - Copy, customize, and run immediately with [PowerShell 7][]
* **[Pickup Service][] integration** - Files written in the correct format for asynchronous delivery
* **Randomized data** - Realistic cities, order IDs, timestamps, and processing times

>[!TIP]
>**Use cases:** Demo environments, load testing, training sessions, performance testing, and testing :Nodinite: logging infrastructure.

>[!INFO]
>**PowerShell 7 required:** This script uses [PowerShell 7][] features like improved JSON handling, better UTF-8 support, and cross-platform compatibility. [Install PowerShell 7][PowerShell 7] if you haven't already.
>
>:fa-flask: **Need exception testing?** For generating .NET exception chains (Azure Functions, database errors), see [Generate Exception Log Events][].

**Jump to section:** [Understanding Log Event Generation](#understanding-log-event-generation) | [Batch Generation](#batch-generation-order-events) | [Script Details](#generatenodinitelogeventsps1)  

## Understanding Log Event Generation

:Nodinite: [Log Events][Log Event] are JSON files that contain structured logging data. When you need to test your logging infrastructure or create demo environments, manually creating hundreds of events is impractical. This [PowerShell 7][] script automates the process by:

* **Generating valid JSON** - Each file matches the [Log Event][] schema
* **Simulating realistic data** - Random cities, order IDs, timestamps, and processing times
* **Base64-encoding payloads** - The `Body` field contains base64-encoded JSON (as required)
* **Randomizing timestamps** - Events scattered throughout earlier today (simulates organic traffic)
* **Adding context properties** - Business identifiers like Order IDs and cities for searchability

The generated files can be consumed by the [Pickup Service][] for asynchronous delivery to the [Log API][], or sent directly to the Log API with [Log using REST][]. The [Logging Service][] then processes them.

**Why PowerShell 7?** [PowerShell 7][] provides better JSON handling with `ConvertTo-Json -Depth`, improved UTF-8 encoding without BOM, and cross-platform compatibility. These features ensure the generated Log Events are correctly formatted for :Nodinite:.

**Learn more:** [Log Event structure][Log Event] | [JSON Log Event schema][JSON Log Event] | [Pickup Service overview][Pickup Service] | [Install PowerShell 7][PowerShell 7]  

## Batch Generation: Order Events

Generate multiple order events with randomized data for demo or load testing purposes.

**Configuration options:** Customize `LogAgentValueId`, `EndPointName`, `MessageType`, and order count parameters. Files are written to the specified output folder in UTF-8 format (no BOM) for compatibility with the [Pickup Service][].

### Usage (quick)

Open [PowerShell 7][] terminal and run:

```powershell
pwsh .\Generate-Nodinite-LogEvents.ps1 -OrderCount 150 -OutputFolder 'C:\temp\logevents'
```

This will create 150 JSON files in the target folder with LogDateTime values scattered earlier today.

>:fa-terminal: **Verify PowerShell 7:** Run `$PSVersionTable.PSVersion` to confirm you're using PowerShell 7.0 or later. [Download PowerShell 7][PowerShell 7] if needed.

### Script: Generate-Nodinite-LogEvents.ps1 {#generatenodinitelogeventsps1}

Save this file next to your documentation or in a demo folder. It uses [PowerShell 7][] features for improved JSON handling and UTF-8 encoding.

```powershell
#!/usr/bin/env pwsh
#Requires -Version 7.0
<#
.SYNOPSIS
Generates Nodinite-style LogEvent JSON files for demo/load-testing.

.DESCRIPTION
This PowerShell 7 script creates realistic Log Event JSON files for testing Nodinite.
* Requires PowerShell 7.0 or later
* Each file contains a single LogEvent object
* UTF-8 encoding without BOM
* Randomized data for realistic testing

.PARAMETER OrderCount
Number of order events to generate (default: 150)

.PARAMETER OutputFolder
Destination folder for generated JSON files (default: C:\temp\logevents)

.EXAMPLE
pwsh .\Generate-Nodinite-LogEvents.ps1 -OrderCount 150 -OutputFolder 'C:\temp\logevents'
#>
param(
    [int]$OrderCount = 150,
    [string]$OutputFolder = 'C:\temp\logevents',
    [int]$RowsMin = 1,
    [int]$RowsMax = 9,
    [int]$LogAgentValueId = 42,
    [string]$EndPointName = 'INT101: Demo Log Events',
    [string]$MessageType = 'Demo.Order/1.0'
)

# Ensure folder exists
if (-not (Test-Path -Path $OutputFolder)) {
    New-Item -Path $OutputFolder -ItemType Directory -Force | Out-Null
}

# City list for variety
$cities = @(
    'New York','London','Tokyo','Sydney','Mumbai','São Paulo','Cairo','Nairobi','Moscow','Berlin',
    'Paris','Madrid','Rome','Lisbon','Oslo','Stockholm','Helsinki','Reykjavik','Dubai','Singapore',
    'Hong Kong','Seoul','Beijing','Jakarta','Bangkok','Manila','Mexico City','Vancouver','Toronto','Los Angeles'
)

# Helper: base64 encode text
function To-Base64([string]$text) {
    return [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($text))
}

# Determine a start time "some time ago today" (random earlier time today)
$now = Get-Date
$maxHours = [Math]::Max(1, $now.Hour)
$startHour = Get-Random -Minimum 1 -Maximum ($maxHours + 1)
$startMinute = Get-Random -Minimum 0 -Maximum 59
$startSecond = Get-Random -Minimum 0 -Maximum 59
$startDate = $now.Date.AddHours($startHour).AddMinutes($startMinute).AddSeconds($startSecond)

# If startDate is in the future, fallback to now
if ($startDate -gt $now) {
    $startDate = $now.AddMinutes(-(Get-Random -Minimum 1 -Maximum 60))
}

Write-Host "Generating $OrderCount events starting around: $($startDate.ToString('o'))" -ForegroundColor Cyan

$current = $startDate.ToUniversalTime()

for ($i = 1; $i -le $OrderCount; $i++) {
    # Generate unique order ID: ORD-MMDDHHMM-###
    $orderTimestamp = $current.ToString('MMddHHmm')
    $orderSequence = $i.ToString('D3')
    $orderNumber = "ORD-$orderTimestamp-$orderSequence"
    
    $city = $cities[Get-Random -Minimum 0 -Maximum $cities.Count]
    $rowCount = Get-Random -Minimum $RowsMin -Maximum ($RowsMax + 1)

    $rows = for ($r = 1; $r -le $rowCount; $r++) {
        @{ Id = $r; Amount = (Get-Random -Minimum 1 -Maximum 100) }
    }

    $payload = @{ OrderNumber = $orderNumber; City = $city; Date = $current.ToString('o'); Rows = $rows } | ConvertTo-Json -Depth 5

    # Build the LogEvent object (fields chosen to be compatible with Nodinite JSON Log Event)
    $logEvent = [ordered]@{
        LogAgentValueId = $LogAgentValueId
        EndPointName = $EndPointName
        EndPointUri = "C:\\temp\\pickup"
        EndPointDirection = 0
        EndPointTypeId = 60
        OriginalMessageTypeName = $MessageType
        LogDateTime = $current.ToString('o')
        EventDirection = 0
        ProcessingUser = "DEMO\\Generator"
        SequenceNo = $i
        EventNumber = $i
        LogText = "Demo order generated"
        ApplicationInterchangeId = $orderNumber
        LogStatus = 0
        ProcessName = "DemoOrderProcess"
        ProcessingMachineName = $env:COMPUTERNAME
        ProcessingModuleName = "Generate-Nodinite-LogEvents.ps1"
        ProcessingModuleType = "DemoGenerator"
        ProcessingTime = (Get-Random -Minimum 10 -Maximum 300)
        Body = To-Base64 $payload
        Context = @{ OrderNumber = $orderNumber; City = $city }
    }

    $json = $logEvent | ConvertTo-Json -Depth 10

    $fileName = "LogEvent_{0}_{1}.json" -f $orderNumber, ([guid]::NewGuid())
    $filePath = Join-Path -Path $OutputFolder -ChildPath $fileName

    # Write UTF8 no BOM
    [System.IO.File]::WriteAllText($filePath, $json, [System.Text.Encoding]::UTF8)

    # Advance current by a few to tens of seconds (randomized)
    $current = $current.AddSeconds((Get-Random -Minimum 5 -Maximum 300))

    if ($i % 50 -eq 0) { Write-Host "  Created $i/$OrderCount events..." -ForegroundColor Green }
}

Write-Host "Done. Files written to: $OutputFolder" -ForegroundColor Cyan
```

### What This Script Does

* **PowerShell 7 features** - Uses improved `ConvertTo-Json -Depth` and UTF-8 encoding without BOM
* **Randomizes data** - Each order gets a random city from 30+ options and 1-9 order rows
* **Realistic timestamps** - Events scattered throughout earlier today (simulates organic traffic)
* **Base64 encoding** - Payload JSON is automatically base64-encoded in the `Body` field
* **Context properties** - Includes `OrderNumber` and `City` for searchability in [Log Views][]
* **Processing metadata** - Sets `ProcessingTime`, `ProcessingMachineName`, and other [Log Event][] properties

**Next steps:** Place generated files in the [Pickup Service][] input folder, or post them directly to the [Log API][] as described in [Log using REST][].

>:fa-info-circle: **Compatibility note:** This script requires [PowerShell 7][] or later. The `#Requires -Version 7.0` directive ensures the script won't run on older PowerShell versions.

## Customizing the Script

### Configuration Parameters

The script accepts several parameters to customize the generated events:

| Parameter | Default | Description |
| --- | --- | --- |
| **OrderCount** | 150 | Number of order [Log Events][Log Event] to generate |
| **OutputFolder** | `C:\temp\logevents` | Destination folder for the [JSON Log Event][] files |
| **RowsMin** | 1 | Minimum number of order rows per event |
| **RowsMax** | 9 | Maximum number of order rows per event |
| **LogAgentValueId** | 42 | [Log Agent][Log Agents] ID (must exist in your Nodinite configuration) |
| **EndPointName** | `INT101: Demo Log Events` | [Endpoint][Endpoints] name displayed in [Log Views][] |
| **MessageType** | `Demo.Order/1.0` | [Message Type][Message Types] for categorization |

### Example Customizations

#### Generate 500 Events for a Specific Log Agent

```powershell
pwsh .\Generate-Nodinite-LogEvents.ps1 -OrderCount 500 -LogAgentValueId 123 -EndPointName "SAP Order Integration"
```

#### Generate Small Events for Performance Testing

```powershell
pwsh .\Generate-Nodinite-LogEvents.ps1 -OrderCount 1000 -RowsMin 1 -RowsMax 3
```

#### Generate Large Events for Payload Size Testing

```powershell
pwsh .\Generate-Nodinite-LogEvents.ps1 -OrderCount 100 -RowsMin 10 -RowsMax 20
```

>[!TIP]
>**Tip:** For correlated multi-step flows (receive/send pairs), review the [O2C Demo Data Script][] and adapt its correlation IDs (`{PREFIX}-{YYYYMMDD}-{HHMM}-{SEQUENCE}`) and step templates.

## Notes & Tips

* **PowerShell 7 required:** This script uses [PowerShell 7][] features. Run `pwsh` command (not `powershell`) to use PowerShell 7. Verify version with `$PSVersionTable.PSVersion`.
* **Cross-platform:** [PowerShell 7][] works on Windows, Linux, and macOS. This script runs on any platform where PowerShell 7 is installed.
* **Direct API posting:** To send events directly to the [Log API][] rather than through the [Pickup Service][], post the JSON to `https://{host}:{port}/LogAPI/api/LogEvent`. The Log API has no API key: it is either open, or it requires an OAuth 2.0 bearer token when **Enable Authentication** is checked in the Portal. See [Log using REST][] for the base URL and samples.
* **Correlation IDs:** For correlated multi-step flows (receive/send pairs), review the [O2C Demo Data Script][] and adapt its correlation IDs.
* **File naming:** The script generates unique filenames with order number and GUID to prevent conflicts when re-running the script.

## Related Scenarios

### Exception Logging

For generating .NET exception chains (Azure Functions, database errors, API failures), see:

* :fa-flask: [Generate Exception Log Events][] - PowerShell 7 script to create realistic exception chains
* :fa-eye: [View Exception Details][] - Learn how to use the v7 exception viewer in Log Views
* :fa-book: [Serilog Integration][Serilog] - Automatic exception logging with Serilog sinks

### Production Logging

For implementing actual logging in applications:

* :fa-code: [Hello World C# Sample][Hello World Sample] - Step-by-step guide to logging with .NET and NuGet
* :fa-cloud: [Log API Overview][Log API] - Send events directly via HTTP POST
* :fa-code: [Log using REST][] - Base URL, OAuth 2.0, and code samples
* :fa-inbox: [Pickup Service][] - Configure asynchronous log event delivery

## :fa-hand-point-right: Next Steps

:fa-flask: [Generate Exception Log Events][] - Create realistic .NET exception chains for testing  
:fa-code: [Hello World C# Sample][Hello World Sample] - Step-by-step guide to logging with .NET and NuGet  
:fa-book: [Serilog Overview][Serilog] - Production logging with Serilog sinks  

## :fa-link-horizontal: Related Topics

:fa-file-code: [JSON Log Event][] - Log Event JSON schema reference  
:fa-cog: [Context Options][] - Add custom context properties  
:fa-traffic-light: [Log Status Codes][] - Error, warning, and success codes  
:fa-search: [Log Views][] - Query and filter logged events  
:fa-chart-line: [Search Fields][] - Extract business data using [Formula][]  
:fa-book: [Log Event][] - Understand the Log Event structure  
:fa-inbox: [Pickup Service][] - Configure asynchronous log event delivery  
:fa-cloud: [Log API][] - Send events directly via HTTP POST  

[Context Options]:{ndr}/Core%20Services/Log%20Event/Features/Context%20Options.md
[Endpoints]:{ndr}/Repository%20Model/Endpoints/Overview.md
[Formula]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Overview.md
[Generate Exception Log Events]:{ndr}/Core%20Services/Log%20API/Troubleshooting/FAQ%20-%20Generate%20Exception%20Log%20Events.md
[Hello World Sample]:{ndr}/Core%20Services/Log%20API/Troubleshooting/FAQ%20-%20Hello%20World%20-%20.NET%20Sample.md
[JSON Log Event]:{ndr}/Core%20Services/Log%20Event/Features/JSON%20Log%20Event.md
[Log Agents]:{ndr}/Administration/1.%20Log%20Management/3.%20Log%20Agents/Features/What%20is%20a%20Log%20Agent.md
[Log API]:{ndr}/Core%20Services/Log%20API/Overview.md
[Log Event]:{ndr}/Core%20Services/Log%20Event/Overview.md
[Log Status Codes]:{ndr}/Administration/1.%20Log%20Management/3.%20Log%20Agents/Features/What%20is%20a%20Log%20Status%20Code.md
[Log using REST]:{ndr}/Core%20Services/Log%20API/Features/Log%20using%20REST.md
[Log Views]:{ndr}/Administration/1.%20Log%20Management/1.%20Log%20Views/Features/What%20is%20a%20Log%20View.md
[Logging Service]:{ndr}/Core%20Services/Logging%20Service/Overview.md
[Message Types]:{ndr}/Repository%20Model/Message%20Types/Overview.md
[O2C Demo Data Script]:{ndr}/Repository%20Model/BPMs/Examples/Order-to-Cash/Generate-O2C-Demo-Data-Script.md
[Pickup Service]:{ndr}/Logging%20and%20Monitoring/Pickup%20LogEvents%20Service/Overview.md
[PowerShell 7]:https://learn.microsoft.com/en-us/powershell/scripting/install/install-powershell-on-windows
[Search Fields]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/What%20is%20a%20Search%20Field.md
[Serilog]:{ndr}/Logging%20and%20Monitoring/Serilog/Overview.md
[View Exception Details]:{ndr}/Getting%20Started/2.%20Log/View%20Exception%20Details.md