---
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 <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> 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

<aside aria-label="Tip" class="nodinite-note nodinite-note--tip">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-lightbulb"></i> Tip</p>
<div class="nodinite-note__content"><p><strong>Use cases:</strong> Demo environments, load testing, training sessions, performance testing, and testing <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> logging infrastructure.</p></div>
</aside>

<aside aria-label="Info" class="nodinite-note nodinite-note--info">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-square-info"></i> Info</p>
<div class="nodinite-note__content"><p><strong>PowerShell 7 required:</strong> This script uses <a href="https://learn.microsoft.com/en-us/powershell/scripting/install/install-powershell-on-windows">PowerShell 7</a> features like improved JSON handling, better UTF-8 support, and cross-platform compatibility. <a href="https://learn.microsoft.com/en-us/powershell/scripting/install/install-powershell-on-windows">Install PowerShell 7</a> if you haven't already.</p><p><i class="fal fa-flask" aria-hidden="true"></i> <strong>Need exception testing?</strong> For generating .NET exception chains (Azure Functions, database errors), see <a href="https://docs.nodinite.com/core-services/log-api/troubleshooting/faq-generate-exception-log-events/">Generate Exception Log Events</a>.</p></div>
</aside>

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

## Understanding Log Event Generation

<span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> [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 <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span>.

**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.

><i class="fal fa-terminal" aria-hidden="true"></i> **Verify PowerShell 7:** Run `$PSVersionTable.PSVersion` to confirm you're using PowerShell 7.0 or later. [Download PowerShell 7][PowerShell 7] if needed.

<h3 id="generatenodinitelogeventsps1">Script: Generate-Nodinite-LogEvents.ps1</h3>

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][].

><i class="fal fa-info-circle" aria-hidden="true"></i> **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
```

<aside aria-label="Tip" class="nodinite-note nodinite-note--tip">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-lightbulb"></i> Tip</p>
<div class="nodinite-note__content"><p><strong>Tip:</strong> For correlated multi-step flows (receive/send pairs), review the <a href="https://docs.nodinite.com/repository-model/bpms/examples/order-to-cash/generate-o2c-demo-data-script/">O2C Demo Data Script</a> and adapt its correlation IDs (<code>{PREFIX}-{YYYYMMDD}-{HHMM}-{SEQUENCE}</code>) and step templates.</p></div>
</aside>

## 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:

* <i class="fal fa-flask" aria-hidden="true"></i> [Generate Exception Log Events][] - PowerShell 7 script to create realistic exception chains
* <i class="fal fa-eye" aria-hidden="true"></i> [View Exception Details][] - Learn how to use the v7 exception viewer in Log Views
* <i class="fal fa-book" aria-hidden="true"></i> [Serilog Integration][Serilog] - Automatic exception logging with Serilog sinks

### Production Logging

For implementing actual logging in applications:

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

## <i class="fal fa-hand-point-right" aria-hidden="true"></i> Next Steps

<i class="fal fa-flask" aria-hidden="true"></i> [Generate Exception Log Events][] - Create realistic .NET exception chains for testing  
<i class="fal fa-code" aria-hidden="true"></i> [Hello World C# Sample][Hello World Sample] - Step-by-step guide to logging with .NET and NuGet  
<i class="fal fa-book" aria-hidden="true"></i> [Serilog Overview][Serilog] - Production logging with Serilog sinks  

## <i class="fal fa-link-horizontal" aria-hidden="true"></i> Related Topics

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

[Context Options]:https://docs.nodinite.com/core-services/log-event/features/context-options/
[Endpoints]:https://docs.nodinite.com/repository-model/endpoints/overview/
[Formula]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/overview/
[Generate Exception Log Events]:https://docs.nodinite.com/core-services/log-api/troubleshooting/faq-generate-exception-log-events/
[Hello World Sample]:https://docs.nodinite.com/core-services/log-api/troubleshooting/faq-hello-world-net-sample/
[JSON Log Event]:https://docs.nodinite.com/core-services/log-event/features/json-log-event/
[Log Agents]:https://docs.nodinite.com/administration/log-management/log-agents/features/what-is-a-log-agent/
[Log API]:https://docs.nodinite.com/core-services/log-api/overview/
[Log Event]:https://docs.nodinite.com/core-services/log-event/overview/
[Log Status Codes]:https://docs.nodinite.com/administration/log-management/log-agents/features/what-is-a-log-status-code/
[Log using REST]:https://docs.nodinite.com/core-services/log-api/features/log-using-rest/
[Log Views]:https://docs.nodinite.com/administration/log-management/log-views/features/what-is-a-log-view/
[Logging Service]:https://docs.nodinite.com/core-services/logging-service/overview/
[Message Types]:https://docs.nodinite.com/repository-model/message-types/overview/
[O2C Demo Data Script]:https://docs.nodinite.com/repository-model/bpms/examples/order-to-cash/generate-o2c-demo-data-script/
[Pickup Service]:https://docs.nodinite.com/logging-and-monitoring/pickup-logevents-service/overview/
[PowerShell 7]:https://learn.microsoft.com/en-us/powershell/scripting/install/install-powershell-on-windows
[Search Fields]:https://docs.nodinite.com/administration/log-management/search-fields/features/what-is-a-search-field/
[Serilog]:https://docs.nodinite.com/logging-and-monitoring/serilog/overview/
[View Exception Details]:https://docs.nodinite.com/getting-started/log/view-exception-details/