Full XML/JSON Support
- datasources
- configsources
- eventsources
- batchjobs
- topologysources
The Import-LMLogicModuleFromFile cmdlet allows you to import LogicModules using the latest XML and JSON import endpoints with enhanced features.
Full XML/JSON Support
JSON Only
# Import a datasource from JSON fileImport-LMLogicModuleFromFile -FilePath "C:\LogicModules\datasource.json" -Type datasources
# Import with explicit format specificationImport-LMLogicModuleFromFile -FilePath "C:\LogicModules\datasource.json" -Type datasources -Format json# Import a datasource from XML fileImport-LMLogicModuleFromFile -FilePath "C:\LogicModules\datasource.xml" -Type datasources -Format xml
# Import an eventsourceImport-LMLogicModuleFromFile -FilePath "C:\LogicModules\eventsource.xml" -Type eventsources -Format xml# Read file content and import from variable$fileContent = Get-Content -Path "C:\LogicModules\datasource.json" -RawImport-LMLogicModuleFromFile -File $fileContent -Type datasources -Format jsonPreserve specific fields from existing LogicModules during import (JSON only):
# Preserve the module name during importImport-LMLogicModuleFromFile ` -FilePath "C:\LogicModules\datasource.json" ` -Type datasources ` -Format json ` -FieldsToPreserve NAME
# Preserve multiple configuration settingsImport-LMLogicModuleFromFile ` -FilePath "C:\LogicModules\datasource.json" ` -Type datasources ` -Format json ` -FieldsToPreserve APPLIES_TO_SCRIPT
# Preserve collection intervalsImport-LMLogicModuleFromFile ` -FilePath "C:\LogicModules\datasource.json" ` -Type datasources ` -Format json ` -FieldsToPreserve COLLECTION_INTERVAL| Field | Description |
|---|---|
NAME | Preserve the name of the LogicModule |
APPLIES_TO_SCRIPT | Preserve the appliesToScript |
COLLECTION_INTERVAL | Preserve the collectionInterval |
ACTIVE_DISCOVERY_INTERVAL | Preserve the activeDiscoveryInterval |
ACTIVE_DISCOVERY_FILTERS | Preserve the activeDiscoveryFilters |
MODULE_GROUP | Preserve the moduleGroup |
DISPLAY_NAME | Preserve the displayName |
USE_WILD_VALUE_AS_UUID | Preserve the useWildValueAsUuid |
DATAPOINT_ALERT_THRESHOLDS | Preserve the datapointAlertThresholds |
TAGS | Preserve the tags |
Control how the import handles existing LogicModules with the same name (JSON only):
# 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 detectedImport-LMLogicModuleFromFile ` -FilePath "C:\LogicModules\datasource.json" ` -Type datasources ` -Format json ` -HandleConflict ERROR# 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}# 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): $_" }}# Advanced import preserving custom settingsImport-LMLogicModuleFromFile ` -FilePath "C:\LogicModules\custom-datasource.json" ` -Type datasources ` -Format json ` -FieldsToPreserve APPLIES_TO_SCRIPT ` -HandleConflict FORCE_OVERWRITE ` -Debug
# Selective import with error handlingtry { 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"}# Functions only support JSON formatImport-LMLogicModuleFromFile ` -FilePath "C:\LogicModules\custom-function.json" ` -Type functions ` -Format json# OIDs only support JSON formatImport-LMLogicModuleFromFile ` -FilePath "C:\LogicModules\custom-oid.json" ` -Type oids ` -Format json# Log sources only support JSON formatImport-LMLogicModuleFromFile ` -FilePath "C:\LogicModules\logsource.json" ` -Type logsources ` -Format json# Diagnostic sources only support JSON format (new in 7.7.0)Import-LMLogicModuleFromFile ` -FilePath "C:\LogicModules\diagnosticsource.json" ` -Type diagnosticsources ` -Format json✅ DO
-Debug to verify import payloads-HandleConflict ERROR first in production❌ DON'T
-Format json for JSON-only typesIf you’re using the old Import-LMLogicModule cmdlet, here’s how to migrate:
# Old way (deprecated)Import-LMLogicModule -FilePath "datasource.xml" -Type "datasource" -ForceOverwrite $true
# New wayImport-LMLogicModuleFromFile -FilePath "datasource.xml" -Type "datasources" -Format "xml" -HandleConflict FORCE_OVERWRITEIssue: “File upload type must be .json”
# Make sure the format matches your file typeImport-LMLogicModuleFromFile -FilePath "module.json" -Type datasources -Format json # ✓ CorrectImport-LMLogicModuleFromFile -FilePath "module.json" -Type datasources -Format xml # ✗ WrongIssue: “This command requires PS version 6.1 or higher”
# Check your PowerShell version$PSVersionTable.PSVersion
# Upgrade to PowerShell 7+ for best compatibility# https://github.com/PowerShell/PowerShell/releasesIssue: “Module type ‘logsources’ only supports JSON format”
# Some types only support JSON - don't try to import XMLImport-LMLogicModuleFromFile -FilePath "logsource.json" -Type logsources -Format json # ✓ CorrectImport-LMLogicModuleFromFile -FilePath "logsource.xml" -Type logsources -Format xml # ✗ Not supported