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

powershell script to search node and delete

$
0
0

Please note that this script was based on this thwack message.

All I did was to change the swsql query used to get the URI and to search and delete a node via PowerShell

 

# This script will search for  node and delete it if exists

#

################################## Attention ###############################################

# You must have Orion SDK installed and set-execution policy must be set to unrestricted!!#

#Before running you must setup your hashed encrypted password using the line below.       #

###########################################################################################

 

#### Prerequisites ###

#  run the line below save credentials to be used by this script on a encrypted file

#GET-CREDENTIAL –Credential "EnterTheOrionUserNamehere” | EXPORT-CLIXML C:\Scripts\SecureCredentialsSAM.xml

## Load the SolarWinds Powershell snapin.

##Needed in order to execute the script.

##Requires the Orion SDK 2.0 installed on the machine this script is running from.

Add-PSSnapinSwisSnapin

# SolarWinds username and password section.

# It is recommended to use a local account create within SAM with only. I strongly recommend that you don't use a MS local account or domain account.

# This section allows the password to be embedded in this script. Without it, the script will not work.

#This is using the hashed encrypted password

$MyCredentials=IMPORT-CLIXMLC:\Scripts\SecureCredentialsSam.xml

$ORIONSERVERNAME= 'yourserver.domain.com'

#This is connecting to SAM to pull the info we need need with the info given

$swis=Connect-Swis-Credential$MyCredentials-host$orionservername

$nodename=read-host"Enter node Name"

$nodeuri=Get-SwisData$swis"SELECT Uri FROM Orion.Nodes WHERe NodeName LIKE '%$nodename'"

if (!$nodeuri) {Write-Host"node does not exist on SAM"}

if ($nodeuri) {

Write-Host"node exist, uri: $nodeuri"

Remove-SwisObject$swis$nodeUri

Write-Host"node has been removed"

}


Viewing all articles
Browse latest Browse all 2677

Trending Articles