Quantcast
Channel: THWACK: All Content - Orion SDK
Viewing all articles
Browse latest Browse all 2677

Export Orion Maps [PowerShell]

$
0
0

UPDATE: Updated to 1.0.1 to fix exports of User Graphics Files

 

Because I'm constantly creating and destroying Orion instances in my currently capacity, I sometimes forget to export everything before I start working on the next instance.  To that end, I started playing around with the Orion SDK and seeing if there was a way that I could rapidly export some content.  The first thing time that I had this was when I stood up a new server and wanted to use my existing Network Path Troubleshooting map.  I started to dig around a little bit and what to my wondering eyes should appear?  No, not reindeer, but a 'table' called MapStudioFiles.

 

Then I broke out my PoSH hat and started tinkering.  This is what I came up with:


<#

------------------------------------------------------------------------------------------------------

File Name:    Export-OrionMapFiles.ps1

Author:      Kevin M.  Sparenberg (https://thwack.solarwinds.com/people/KMSigma)

------------------------------------------------------------------------------------------------------

Purpose:

  This script will  export the Orion Maps (and associated files) from an active Orion System.  By

default this script will export ALL maps and associated files  (including images).  To change it to

only export hteOrionMap files comment out or remove the "Exports only the Maps" region.

  Export Path is to the  current user's desktop.  This can be  modified within the "Setup Variables &

Connect to the SolarWinds Information Service (SWIS)"  region.

IMPORTANT NOTE:

This version is set to use the "username/password"  authentication process.  This can be  changed to

AD-credentials with some minor tweaking (TBD).

Prerequisites:

  You must have OrionSDK Installed (Link:  https://thwack.solarwinds.com/community/labs_tht/orion-sdk)

  (tested with version 1.10)

Version History: [P = Past, C = Current, F = Future]

  (P) 1.0.0 - Initial  Release (2015-07-22)

  (C) 1.0.1 - Update  the path check for custom icons (2015-08-10)

  (F) 1.1.0 -  Conversion to a PowerShell Function (TBD)

  (F) 1.2.0 - Allow for  Multiple Authentication Types (TBD)

Tested against:

  Orion Platform  2015.1.2

  SAM 6.2.1

  DPA 9.2.0

  QoE 2.0

  IPAM 4.3

  NCM 7.4

  NPM 11.5.2

  NTA 4.1.1

  OGS 1.0.10

  WPM 2.2.0

  SRM 6.1.11

  Toolset 11.0.1

  UDT 3.2.2

  IVIM 2.1.0

  VNQM 4.2.2

------------------------------------------------------------------------------------------------------

#>

#region Setup Variables & Connect to the SolarWinds  Information Service (SWIS)

Add-PSSnapin-NameSwisSnapin-ErrorActionSilentlyContinue

# The username for a user with admin  level permissions

$SwisUsername="admin"

# Thepoassword for said user (in plain text)

$SwisPassword="@ppStack1"

# The IP, machine name, or alias for the associated Orion  Instance

$SwisHost    ="orionweb.demo.lab"

$SwisCredentails=New-Object-TypeNameSystem.Management.Automation.PSCredential-ArgumentList$SwisUsername,( ConvertTo-SecureString$SwisPassword-AsPlainText-Force )

# Export Path for the Files

$ExportPath="$env:userprofile\Desktop\OrionMapFiles"

#endregion

#region Exports the Maps and any associated files

$SwqlQuery=@"

SELECT FileName, FileData

FROM Orion.MapStudioFiles

WHERE FileType = 0 AND IsDeleted = False

ORDER BY FileName

"@

#endregion

#region Exports only the Maps

$SwqlQuery=@"

SELECT FileName, FileData

FROM Orion.MapStudioFiles

WHERE IsDeleted = False

ORDER BY FileName

"@

#endregion

#region Collect the files to a local object

$SwisConnection  =Connect-Swis-Hostname$SwisHost-Credential$SwisCredentails

$OrionMapFiles=Get-SwisData-SwisConnection$SwisConnection-Query$SwqlQuery

$SwisConnection.Close()

$SwisConnection.Dispose()

Remove-Variable-NameSwisConnection-Force-Confirm:$false-ErrorActionSilentlyContinue

$TotalMapFiles=$OrionMapFiles.Count

#endregion

#region Check for Path Existence.  If the path doesn't exist, then it's created.

if ( -not ( Test-Path-Path$ExportPath-ErrorActionSilentlyContinue ) )

{

    Write-Host"Path: '$ExportPath' does not  exist.`nCreating Export  Folder..."-ForegroundColorYellow

    New-Item-ItemTypeDirectory-Path$ExportPath|Out-Null

}

#endregion

#region Cycle through each file and export to the file system

For( $i=0; $i-lt$TotalMapFiles; $i++ )

{

    Write-Progress-Activity"Exporting  Orion Map Files"-CurrentOperation"Exporting $($OrionMapFiles[$i].FileName)"-Status"Exporting $($OrionMapFiles[$i].FileData.Length) bytes"-PercentComplete ( ( $i/$TotalMapFiles ) *100 )

    #region Added  for verison 1.0.1 for Custom Icons

    # Check for  the "Full Path" and create it, if it doesn't exist.

    $ExportFullPath=( Join-Path-Path$ExportPath-ChildPath$OrionMapFiles[$i].FileName )

    $ExportDirectory=Split-Path-Path$ExportFullPath-Parent

    if ( -not ( Test-Path-Path$ExportDirectory-ErrorActionSilentlyContinue ) )

    {

        Write-Warning"Creating [$($ExportDirectory)] Folder"

        New-Item-Path$ExportDirectory-ItemTypeDirectory|Out-Null

    }

    #endregion

    $OrionMapFiles[$i].FileData|Set-Content-Path ( Join-Path-Path$ExportPath-ChildPath$OrionMapFiles[$i].FileName ) -EncodingByte-Force

}

Remove-VariableOrionMapFiles

Write-Progress-Activity"Exporting Orion Map Files"-Completed

#endregion


I'd love feedback from the community on what you think about this and what you think of my plans going forward.


Viewing all articles
Browse latest Browse all 2677

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>