Mass Export of NCM Device Templates

Do you run a bunch of Orion servers?  Do you hate exporting your custom NCM Device Templates one at a time?

No?  Only me?

Well, if you are ever like me, I’ve got something to help you out.

It basically checks for all the device templates in your database for those that aren’t out of the box and exports them in the proper format.

<######################################################################
Name:   Export-DeviceTemplates.ps1
Author: Kevin M. Sparenberg
-----------------------------------------------------------------------
Purpose: Export all non-default NCM Device Templates from Orion Server

Version History:
1.0 - 01AUG2017 - Initial Build

Notes:
Change the elements in the Declare Variables region to your own needs
######################################################################>

#region Declare Variables
# Export Path in Local File System
$ExportPath = "$env:USERPROFILE\Downloads\DeviceTemplates"

# Test Export Path & Create folder if doesn't exist
if ( -not ( Test-Path -Path $ExportPath -ErrorAction SilentlyContinue ) )
{
    Write-Warning -Message "Creating Folder at $ExportPath"
    New-Item -Path $ExportPath -ItemType Directory | Out-Null
}


# Orion Username & Password & Host (Name or IP)
$SwisUsername = "admin" 
$SwisPassword = "SuperSecret"
$SwisHost     = "127.0.0.1"

# SWQL Query for Templates
# Only includes non-default (last line)
# To include all templates, remove the WHERE clause
$Swql = @"
SELECT TemplateName
     , SystemOID
     , TemplateXml
FROM Cirrus.DeviceTemplates
WHERE IsDefault <> 'True'
"@
#endregion Declare Variables

#region Connect to SWIS
$SwisCredentails = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $SwisUsername, ( ConvertTo-SecureString $SwisPassword -AsPlainText -Force )
$SwisConnection = Connect-Swis -Hostname $SwisHost -Credential $SwisCredentails
#endregion Connect to SWIS


# Query for all "non-default" Templates
$DeviceTemplates = Get-SwisData -SwisConnection $SwisConnection -Query $Swql

#region Export Templates to File System
ForEach ( $DeviceTemplate in $DeviceTemplates )
{
    $FileName = "$( $DeviceTemplate.TemplateName )-$( $DeviceTemplate.SystemOID ).ConfigMgmt-Commands"
    $DeviceTemplate.TemplateXml | Out-File -FilePath ( Join-Path -Path $ExportPath -ChildPath $FileName ) -Encoding ascii -Force -Confirm:$false
}
#endregion Export Templates to File System

1 thought on “Mass Export of NCM Device Templates”

  1. Thanks for this Kevin, came in handy migrating an NCM instance into our main instance

    FYI Cirrus.DeviceTemplates has changed to Cli.DeviceTemplates

    Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.