Hello there,
First post
- apologies if I neglect some rules and whatnot. 2 Questions, below:
1) I'm looking for a way to extract NCM Jobs from Solarwinds via the Powershell SDK to determine which jobs are disabled, when they were created, when they were last modified, if they are currently scheduled, if so when.. etc. in the hopes of finding some jobs I can delete that are no longer used. Does anyone have equivalent powershell to spit out a list of all the NCM jobs and their properties?
2) I have powershell code for collecting all nodes in Solarwinds below.. spitting out to shell which machines are down, unknown, unmanaged etc. but it does not seem to be collecting unmanagedfrom and unmanageduntil times correctly... I have heard this is in UTC time and found someone elses code to convert the values found.. but it looks as though quite a lot (all?) of my values are blank for these two fields, and so powershell has nothing to convert from.. is my code wrong for gathering the unmanagedfrom and unmanageduntil bits for a particular node?
Powershell for the all nodes as follows:
logfolder = "$WorkingDirectory\Output\"
# If log path doesn't exist create it..
If (!(Test-Path -Path "$logfolder" -ErrorAction SilentlyContinue)) { New-Item "$logfolder" -Type Directory -ErrorAction SilentlyContinue | Out-Null }
$timestamp = Get-Date -format "yyyy_MM_dd_HHmmss"
$resultfile = $logfolder + "Solarwinds_Get_All_Nodes" + "_" + $Timestamp + ".csv"
# pre-stage the log file (NO APPEND ON THIS ONE) -encoding ASCII makes it a file that can be read by Excel as csv
"MachineName,LogEntry,Status,Timestamp" | Out-File -LiteralPath $ResultFile -encoding ASCII
if($PSVersionTable.PSVersion.Major -lt 3){$WorkingDirectory = split-path -parent $MyInvocation.MyCommand.Definition}
else{$WorkingDirectory = $PSScriptRoot}
$Nodestodelete = gc $WorkingDirectory\Input\input.txt
$hostname = "melymgmt37.oceania.cshare.net"
#$password = New-Object System.Security.SecureString
$SnapintoLoad = 'SwisSnapin'
Add-PSSnapin $Snapintoload
# Load the SwisSnapin if not already loaded
if (!(Get-PSSnapin | where {$_.Name -eq "$SnapintoLoad"})) {
Add-PSSnapin "$SnapintoLoad" -erroraction SilentlyContinue -errorvariable $e | out-null
}
# Get the ofset between local time and UTC (Orion displays unmanaged machines in UTC time)
[string]$strBaseOffset = [TimeZoneInfo]::Local | select BaseUtcOffset
$timeOffset = ($strBaseOffset -split '=|:')[1]
#check that it actually loaded properly...
$Getdemsnaps = Get-PSSnapin
if ($getdemsnaps -like "*SwisSnapin*") {
#$credential = New-Object System.Management.Automation.PSCredential($username,$password)
$swis = Connect-Swis -Hostname $hostname
# Get-SwisData $swis "SELECT Name FROM Metadata.Property where EntityName = 'Orion.Nodes'" # get metadata from all properties of Nodes
#Get all the nodes
$Nodes = Get-SwisData $swis 'SELECT Caption, uri, Status, Pollinterval FROM Orion.Nodes'
# Address the Timezone Conversion
# ------ Define time related calculated properties
$umFrom = @{Label="Unmanage From"; Expression = {($_.UnManageFrom).addhours($timeOffset)}}
$umUntil = @{Label="Unmanage Until"; Expression = {($_.UnManageUntil).addhours($timeOffset)}}
foreach ($Node in $Nodes) {
if ($Node.status -eq 0) {
Write-Host -foregroundcolor blue "$($node.Caption) is Unknown"
"$($node.caption),unknown,status,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss:$((Get-Date).millisecond)")" | Out-File -literalpath $Resultfile -append
}
elseif ($Node.Status -eq 1) {
#Write-Host -foregroundcolor green "$($node.Caption) is Up"
"$($node.caption),UP,status,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss:$((Get-Date).millisecond)")" | Out-File -literalpath $Resultfile -append
}
elseif ($Node.status -eq 2) {
Write-Host -foregroundcolor red "$($node.Caption) is Down"
"$($node.caption),down,status,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss:$((Get-Date).millisecond)")" | Out-File -literalpath $Resultfile -append
}
elseif ($Node.status -eq 9) {
Write-Host -foregroundcolor cyan "$($node.Caption) is Unmanaged - from: $umFrom until: $umUntil"
"$($node.caption),Unmanaged from $umfrom to $umUntil,status,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss:$((Get-Date).millisecond)")" | Out-File -literalpath $Resultfile -append
}
elseif (($Node.status -ne 0) -and ($node.status -ne 1) -and ($node.status -ne 2) -and ($node.status -ne 9)) {
Write-Host -foregroundcolor yellow "$($node.Caption) is uh...something different, status is: $($Node.Status)"
}
}
}
else {
Write-Host "$snapintoload failed to load"
Write-host "Probably means you haven't downloaded Orion SDK OR in rare cases have not run the following commands - which occasionally the SDK installer will fail to do automatically:"
Write-host "'C:\Windows\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe "C:\Program Files (x86)\SolarWinds\Orion SDK\SWQL Studio\SwisPowerShell.dll"'"
Write-host "'C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files (x86)\SolarWinds\Orion SDK\SWQL Studio\SwisPowerShell.dll"'"
Write-Host Error was: $e
"Nope,Failed to load snappin,status,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss:$((Get-Date).millisecond)")" | Out-File -literalpath $Resultfile -append
}
explorer.exe $logfolder