Skip to content

LogicModule Management

Import LogicModules

The Import-LMLogicModuleFromFile cmdlet allows you to import LogicModules using the latest XML and JSON import endpoints with enhanced features.

Supported Module Types

Full XML/JSON Support

  • datasources
  • configsources
  • eventsources
  • batchjobs
  • topologysources

JSON Only

  • logsources
  • oids
  • functions
  • diagnosticsources

Basic Import Examples

Terminal window
# Import a datasource from JSON file
Import-LMLogicModuleFromFile -FilePath "C:\LogicModules\datasource.json" -Type datasources
# Import with explicit format specification
Import-LMLogicModuleFromFile -FilePath "C:\LogicModules\datasource.json" -Type datasources -Format json

Advanced Import Options

Field Preservation

Preserve specific fields from existing LogicModules during import (JSON only):

Terminal window
# Preserve the module name during import
Import-LMLogicModuleFromFile `
-FilePath "C:\LogicModules\datasource.json" `
-Type datasources `
-Format json `
-FieldsToPreserve NAME
# Preserve multiple configuration settings
Import-LMLogicModuleFromFile `
-FilePath "C:\LogicModules\datasource.json" `
-Type datasources `
-Format json `
-FieldsToPreserve APPLIES_TO_SCRIPT
# Preserve collection intervals
Import-LMLogicModuleFromFile `
-FilePath "C:\LogicModules\datasource.json" `
-Type datasources `
-Format json `
-FieldsToPreserve COLLECTION_INTERVAL

Available Fields to Preserve

FieldDescription
NAMEPreserve the name of the LogicModule
APPLIES_TO_SCRIPTPreserve the appliesToScript
COLLECTION_INTERVALPreserve the collectionInterval
ACTIVE_DISCOVERY_INTERVALPreserve the activeDiscoveryInterval
ACTIVE_DISCOVERY_FILTERSPreserve the activeDiscoveryFilters
MODULE_GROUPPreserve the moduleGroup
DISPLAY_NAMEPreserve the displayName
USE_WILD_VALUE_AS_UUIDPreserve the useWildValueAsUuid
DATAPOINT_ALERT_THRESHOLDSPreserve the datapointAlertThresholds
TAGSPreserve the tags

Conflict Handling

Control how the import handles existing LogicModules with the same name (JSON only):

Terminal window
# Force overwrite existing modules (default behavior)
Import-LMLogicModuleFromFile `
-FilePath "C:\LogicModules\datasource.json" `
-Type datasources `
-Format json `
-HandleConflict FORCE_OVERWRITE
# Throw an error if a conflict is detected
Import-LMLogicModuleFromFile `
-FilePath "C:\LogicModules\datasource.json" `
-Type datasources `
-Format json `
-HandleConflict ERROR

Bulk Import Operations

Import Multiple LogicModules from Directory

Terminal window
# Import all JSON datasources from a directory
$moduleFiles = Get-ChildItem -Path "C:\LogicModules\datasources" -Filter "*.json"
foreach ($file in $moduleFiles) {
try {
Write-Host "Importing: $($file.Name)" -ForegroundColor Cyan
Import-LMLogicModuleFromFile `
-FilePath $file.FullName `
-Type datasources `
-Format json `
-HandleConflict FORCE_OVERWRITE
Write-Host "✓ Successfully imported: $($file.Name)" -ForegroundColor Green
}
catch {
Write-Warning "Failed to import $($file.Name): $_"
}
# Add small delay to avoid rate limiting
Start-Sleep -Milliseconds 500
}

Import Different Module Types

Terminal window
# Define module files and their types
$modules = @(
@{ Path = "C:\LogicModules\datasource.json"; Type = "datasources"; Format = "json" }
@{ Path = "C:\LogicModules\eventsource.xml"; Type = "eventsources"; Format = "xml" }
@{ Path = "C:\LogicModules\configsource.json"; Type = "configsources"; Format = "json" }
@{ Path = "C:\LogicModules\logsource.json"; Type = "logsources"; Format = "json" }
)
foreach ($module in $modules) {
try {
Import-LMLogicModuleFromFile `
-FilePath $module.Path `
-Type $module.Type `
-Format $module.Format
Write-Host "✓ Imported $($module.Type): $($module.Path)" -ForegroundColor Green
}
catch {
Write-Error "Failed to import $($module.Path): $_"
}
}

Import with Preservation and Conflict Handling

Terminal window
# Advanced import preserving custom settings
Import-LMLogicModuleFromFile `
-FilePath "C:\LogicModules\custom-datasource.json" `
-Type datasources `
-Format json `
-FieldsToPreserve APPLIES_TO_SCRIPT `
-HandleConflict FORCE_OVERWRITE `
-Debug
# Selective import with error handling
try {
Import-LMLogicModuleFromFile `
-FilePath "C:\LogicModules\production-datasource.json" `
-Type datasources `
-Format json `
-FieldsToPreserve NAME `
-HandleConflict ERROR `
-ErrorAction Stop
Write-Host "Import successful - no conflicts detected"
}
catch {
Write-Warning "Import failed - module already exists with this name"
Write-Host "Use -HandleConflict FORCE_OVERWRITE to replace existing module"
}

JSON-Only Module Types

Import Functions

Terminal window
# Functions only support JSON format
Import-LMLogicModuleFromFile `
-FilePath "C:\LogicModules\custom-function.json" `
-Type functions `
-Format json

Import OIDs

Terminal window
# OIDs only support JSON format
Import-LMLogicModuleFromFile `
-FilePath "C:\LogicModules\custom-oid.json" `
-Type oids `
-Format json

Import Log Sources

Terminal window
# Log sources only support JSON format
Import-LMLogicModuleFromFile `
-FilePath "C:\LogicModules\logsource.json" `
-Type logsources `
-Format json

Import Diagnostic Sources

Terminal window
# Diagnostic sources only support JSON format (new in 7.7.0)
Import-LMLogicModuleFromFile `
-FilePath "C:\LogicModules\diagnosticsource.json" `
-Type diagnosticsources `
-Format json

Best Practices

✅ DO

  • Use -Debug to verify import payloads
  • Preserve critical fields when updating existing modules
  • Test with -HandleConflict ERROR first in production
  • Add delays between bulk imports to avoid rate limiting
  • Keep backups of LogicModules before bulk operations

❌ DON'T

  • Don’t import without testing in a sandbox first
  • Don’t forget to specify -Format json for JSON-only types
  • Don’t skip error handling in bulk operations
  • Don’t ignore PowerShell version requirements (6.1+)

Migration from Deprecated Cmdlet

If you’re using the old Import-LMLogicModule cmdlet, here’s how to migrate:

Terminal window
# Old way (deprecated)
Import-LMLogicModule -FilePath "datasource.xml" -Type "datasource" -ForceOverwrite $true
# New way
Import-LMLogicModuleFromFile -FilePath "datasource.xml" -Type "datasources" -Format "xml" -HandleConflict FORCE_OVERWRITE

Troubleshooting

Common Issues

Issue: “File upload type must be .json”

Terminal window
# Make sure the format matches your file type
Import-LMLogicModuleFromFile -FilePath "module.json" -Type datasources -Format json # ✓ Correct
Import-LMLogicModuleFromFile -FilePath "module.json" -Type datasources -Format xml # ✗ Wrong

Issue: “This command requires PS version 6.1 or higher”

Terminal window
# Check your PowerShell version
$PSVersionTable.PSVersion
# Upgrade to PowerShell 7+ for best compatibility
# https://github.com/PowerShell/PowerShell/releases

Issue: “Module type ‘logsources’ only supports JSON format”

Terminal window
# Some types only support JSON - don't try to import XML
Import-LMLogicModuleFromFile -FilePath "logsource.json" -Type logsources -Format json # ✓ Correct
Import-LMLogicModuleFromFile -FilePath "logsource.xml" -Type logsources -Format xml # ✗ Not supported