This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Retrieving Last Backup from VMware and Updating them into SolarWinds.

Based on a reply from @jm_Sysadmin in another thread I decided to see if I could this working for me and made some amendments along the way.  This has been working great for me.  Hopefully it can help someone else.

It requires a Custom Property called: "LastBackedUp"

Also, using the below to store your credentials securely.

Get-Credential | Export-CliXml -Path "C:\Scripts\Credentials\SolarWinds-Credential.xml"
Get-Credential | Export-CliXml -Path "C:\Scripts\Credentials\VCentre-Credential.xml"


$SwisServer = 'SolarWindsServer'
$SWIScreds = Import-CliXml -Path "C:\Scripts\Credentials\SolarWinds-Credential.xml"

$swis = Connect-Swis $SwisServer -Credential $SWISCreds

$Nodes = Get-SwisData -SwisConnection $swis -Query "SELECT NodeID, DisplayName FROM Orion.Nodes"

$VCenterCred = Import-CliXml -Path "C:\Scripts\Credentials\VCentre-Credential.xml"
$VCenter = 'VCentreServer'

Connect-VIServer $VCenter -Credential $VCenterCred

$DateFormat = "dd/MM/yyyy HH:mm:ss"
$SolarWindsDateFormat = "M/d/yyyy h:mm tt"

$Results = @{}

foreach ($VM in $VMs)
{
    $VMNotes = $VM | Get-Annotation -Name "Last Backup"
    if ($VMNotes.Value) {
        $node = $Nodes | Where-Object { $_.DisplayName -eq $VM.Name }
        if ($node) {
            $LastBackupTime = [DateTime]::ParseExact($VMNotes.Value, $DateFormat, $null).ToString($SolarWindsDateFormat)
            $Uri = "swis://localhost/Orion/Orion.Nodes/NodeID=$($node.NodeID)/CustomProperties"
            $CustomProps = @{ LastBackedup = $LastBackupTime }
            Set-SwisObject -SwisConnection $swis -Uri $Uri -Properties $CustomProps
            Write-Host "Updating Orion Node: $($node.DisplayName)" -ForegroundColor Green
        }
    }
}


You can add a scheduled task to run each morning using the below.  Make sure to run the schedule as the user who stored the credentials earlier else it will fail to pull them as credentials can only be accessed by the user who created them.

$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-ExecutionPolicy Bypass -File 'C:\Scripts\ScheduledScripts\Update-SolarWindsLastBackup.ps1'"
$trigger = New-ScheduledTaskTrigger -Daily -At "9:00 AM"
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -DontStopOnIdleEnd
$principal = New-ScheduledTaskPrincipal -UserId "DOMAIN\User" 

Register-ScheduledTask -TaskName "Update-SolarWindsLastBackedUp" -Action $action -Trigger $trigger -Settings $settings -Principal $principal