cancel
Showing results for 
Search instead for 
Did you mean: 
Create Post
Community Manager
Community Manager

"Trim" Domain from Caption Names via PowerShell and Orion SDK

DISCLAIMER below - please review the script in it's entirety before running in your environment.

I, for one, do not like long caption names.  For the Orion web display, I much prefer short names. But after each network discovery, I'm always going in and editing them over and over again to fix it.  I decided to automate this using the Orion SDK.

The below script looks for captions that end in "demo.lab" and update the captions to use my preferred naming scheme.

Before:

KMSigma_0-1592859630175.png

 

After:

KMSigma_1-1592859799476.png

When you run it, it will show you the captions it plans on changing.

KMSigma_2-1592864037864.png

Then you can close that list and answer "y" to change them.

KMSigma_3-1592864076220.png

Then it updates them all

KMSigma_4-1592864096322.png

For completeness, here is the script.

 

 

<#
# TrimDomainFromCaptions.ps1
# Author: Kevin M. Sparenberg (KMSigma [https://thwack.solarwinds.com/t5/user/viewprofilepage/user-id/6])
#
# I personally don't like full domain names in for my caption names.  As such, I normally run something like this to "cleanup" the names.  it can easily be run multiple times for different domains.
#

#>

$DomainMatch = "demo.lab"

Import-Module -Name SwisPowerShell -ErrorAction SilentlyContinue

if ( -not ( $Swis ) )
{
    $Swis = Connect-Swis -Hostname "HostOrIpHere" -UserName 'UsernameHere' -Password 'P@ssw0rdH3r3'
}

# The query logic is as such:
#   Give me the Caption, NodeID, DNS-resolved Name, and URI
#   for all nodes
#   where the caption matches 'something.$DomainMatch'
#   and it's not being polled by ping or external (ie. it is Agent, WMI, or SNMP)

$NodesWithFullDomains = Get-SwisData -SwisConnection $Swis -Query "SELECT Caption, NodeID, DNS, Uri FROM Orion.Nodes WHERE Caption LIKE '%.$( $DomainMatch )' AND ObjectSubType NOT IN ('ICMP', 'External')"

# This is more advanced PowerShell, but I'll explain it here:
# The "Add-Member" function adds a new "column" to the NodesWithFullDomains variable.
# This column is called "NewCaption" (Name) and it's value is calculated ( ScriptProperty type ) from the existing objects ( $this.Caption.Split(".")[0].ToUpper() ).
$NodesWithFullDomains | Add-Member -MemberType ScriptProperty -Name "NewCaption" -Value { $this.Caption.Split(".")[0].ToUpper() } -Force

# Display all the things we'll change
$NodesWithFullDomains | Select-Object -Property Caption, NewCaption | Out-GridView -Title "We'll be updating these elements" -Wait
# Ask if we are good to go.
$GoNoGo = ( Read-Host "Are we good to proceed? [Y/N]" ).ToLower()

if ( $GoNoGo -eq 'y' )
{
    # Cycle through each entry in our list and figure out a better caption name for it
    ForEach ( $Node in $NodesWithFullDomains )
    {
        Write-Host "Updating $( $Node.Caption ) to $( $Node.NewCaption ) " -NoNewline
        # This is the line doing the work
        Set-SwisObject -SwisConnection $Swis -Uri $Node.Uri -Properties @{ Caption = $Node.NewCaption }
        Write-Host "[UPDATED]" -ForegroundColor Green
    }
}
else
{
    Write-Host "No changes were made." -ForegroundColor Yellow
}

 

DISCLAIMER: I make no claims that this will work 100% in your environment.  This has been tested with Orion platform products 2020.2.  Please test in a development environment before executing in production.

"Shoot for the stars to reach the moon"
6 Replies

Nice 🙂

 

Only thing i would say to this is be careful of alerts, If an alert has triggered against an object with the old name you will still see that pop up occassionally.

I saw an article a while back https://thwack.solarwinds.com/t5/NPM-Discussions/Alert-Issue-AlertCaption/m-p/192371#413782 which talks about it and the queries to check with and if desired fixed.

I think this is just another reason to have more (useful) information in email alerts.

I normally give the Caption, IP, DNS, and any pertinent custom properties at the minimum.  Plus a link to the Node Details page and a link to the Alert page.  My take has always been that more details in alerts is (generally) better.

"Shoot for the stars to reach the moon"
Level 20

This is great... really should be an option in the Orion interface though perhaps!

Bill

0 Kudos

Sounds like an excellent item for a Feature Request.

"Shoot for the stars to reach the moon"
0 Kudos

I wholeheartedly agree! Captions shouldn't be FQDN's.

I may update the clean up script I have been using to leverage what some of what you did, and personally, I like to have a report of what needs cleaned up, with a copy of the clean up script next to it. I do this for lots of stuff, interfaces, disk clean up, etc. It empowers other people to assist me easily so that they can do "stuff" while I am out, or cross training, etc. 

jm_sysadmin_1-1592920176737.png

 

 

I like the idea of the remediation script being right there and accessible.  Self-documenting is always better than no documenting.

"Shoot for the stars to reach the moon"
0 Kudos