Private/ConvertTo-SwNode.ps1

Function ConvertTo-SwNode{
    <#
        .SYNOPSIS
        Create a powershell object from [Parmis.Solarwinds.Node] class
 
        .DESCRIPTION
        This function simply get a custom object as an input an convert it to the standard [Parmis.Solarwinds.Node] class
 
        .EXAMPLE
        PS> ConvertTo-SwNode -Object $myCustomObject
        Id : 1234
        Caption : TestNode01
        Name : TestNode01
        DNSName : TestNode01.contoso.com
        IsServer : True
        Type : Agent
        Vendor : Windows
        IP : 192.168.100.50
        MachineType : Windows 2022 Server
        Location : SiteA
        Status : 1
        ChildStatus : 1
        StatusMessage : Node status is Up.
        EngineId : 2
        LastSync : 02/18/2024 10:00:25 AM
        Uri : swis://MainPoller.Contoso.com/Orion/Orion.Nodes/NodeID=1234
    #>

    [Cmdletbinding()]
    [OutputType([Parmis.Solarwinds.Node])]
    Param (
        [Parameter(Mandatory = $true)]
        $Object
    )

    Write-Verbose -Message "Converting to target object ..."
    $output = [Parmis.Solarwinds.Node]::new()

    $output.Id = $Object.NodeID
    $output.Caption = $Object.Caption
    $output.Name = (($Object.Caption).Split(".")[0]).ToUpper()
    $output.IsServer = $Object.IsServer
    $output.Type = $Object.ObjectSubType
    $output.Vendor = $Object.Vendor
    $output.IP = $Object.IP_Address
    $output.MachineType = $Object.MachineType
    $output.Status = $Object.Status
    $output.ChildStatus = $Object.ChildStatus
    $output.StatusMessage = $Object.StatusDescription
    $output.EngineId = $Object.EngineId
    $output.Uri = $Object.Uri

    if (! ($Object.LastSync -is [System.DBNull] -or $Object.LastSync -eq "" )){
        $output.LastSync = $Object.LastSync
    }

    if (! ($Object.NextRediscovery -is [System.DBNull] -or $Object.NextRediscovery -eq "" )){
        $output.NextRediscovery = $Object.NextRediscovery
    }

    if ($Object.DNS -is [System.DBNull] -or $Object.DNS -eq "" ){
        $output.DNSName = $null
    }
    else{
        $output.DNSName = $Object.DNS
    }

    if ($Object.Location -is [System.DBNull] -or $Object.Location -eq "" ){
        $output.Location = $null
    }
    else{
        $output.Location = $Object.Location
    }

    return $output
}