PowerShell Script: Trying to concatenate a string to interface caption.

I'm fairly new to scripting. What command can I use to concatenate a string to interface caption on Line 29-30, wanted to add something like " -DC" to the existing interface caption. I'm trying to modify this script for that Remove Domain and Capitalize Node Captions . It looks like "Concat()" or "+" won't work.

Parents
  • What do your interface captions look like now and what do you want them to look like?

  • Hi Kevin, good day! I'm glad to hear from you.

    I'm trying to bulk edit interface captions from a list of nodes in a text file. I modified your Fix-NodeCaptions to do that. Im just missing the Set-SwisObject to concatenate the interface caption. Back to your question, the interface caption looks like now "ha1" then would like this after "ha1 - (DC-MONITORED)".

    I won't be filtering the interface caption, basically every monitored status: UP interface will be concatenated with " - (DC-MONITORED)"

    Thank you in advance!

  • This is untested but here's an attempt at editing the powershell to do what you need.

    The basic powershell to concat the data you need is on line 20.

    I'd recommend testing this with the Set-SwisObject command removed or commented out at first.

    # Connect to SolarWinds Information Service
    $SwisHost = 'myOrionServer.domain.local'
    $SwisCreds = Get-Credential -Message "Enter the username/password to connect to Orion server on $SwisHost"
    $SwisConnection = Connect-Swis -Hostname $SwisHost -Credential $SwisCreds
    
    # Query for nodes meeting our requirements
    $Swql = @"
    SELECT Caption
         , Status
         , Uri
    FROM Orion.NPM.Interfaces
    WHERE Status = 1
    "@
    
    # Query SWIS
    $InterfacesToUpdate = Get-SwisData -SwisConnection $SwisConnection -Query $Swql
    
     # Cycle through each interface
    ForEach ( $interface in $InterfacesToUpdate ) {
        $NewCaption = $interface.Caption + " - (DC-MONITORED)"
    
        Write-Host "We are updating $( $interface.Caption ) to $( $NewCaption )"
        Set-SwisObject -SwisConnection $SwisConnection -Uri $interface.Uri -Properties @{ Caption = $NewCaption }
    } # end of ForEach loop

Reply
  • This is untested but here's an attempt at editing the powershell to do what you need.

    The basic powershell to concat the data you need is on line 20.

    I'd recommend testing this with the Set-SwisObject command removed or commented out at first.

    # Connect to SolarWinds Information Service
    $SwisHost = 'myOrionServer.domain.local'
    $SwisCreds = Get-Credential -Message "Enter the username/password to connect to Orion server on $SwisHost"
    $SwisConnection = Connect-Swis -Hostname $SwisHost -Credential $SwisCreds
    
    # Query for nodes meeting our requirements
    $Swql = @"
    SELECT Caption
         , Status
         , Uri
    FROM Orion.NPM.Interfaces
    WHERE Status = 1
    "@
    
    # Query SWIS
    $InterfacesToUpdate = Get-SwisData -SwisConnection $SwisConnection -Query $Swql
    
     # Cycle through each interface
    ForEach ( $interface in $InterfacesToUpdate ) {
        $NewCaption = $interface.Caption + " - (DC-MONITORED)"
    
        Write-Host "We are updating $( $interface.Caption ) to $( $NewCaption )"
        Set-SwisObject -SwisConnection $SwisConnection -Uri $interface.Uri -Properties @{ Caption = $NewCaption }
    } # end of ForEach loop

Children