Private/ConvertTo-SwAgent.ps1
Function ConvertTo-SwAgent{ <# .SYNOPSIS Create a powershell object from [Parmis.Solarwinds.Agent] class .DESCRIPTION This function simply get a custom object as an input an convert it to the standard [Parmis.Solarwinds.Agent] class .EXAMPLE PS> ConvertTo-SwAgent -Object $myCustomObject Id : 1234 Guid : a490ae62-15c0-4653-8da0-bc3106f7cf24 Name : TestAgent01 PollingEngineId : 2 AgentStatus : 1 AgentStatusMessage : Agent is running ConnectionStatus : 1 ConnectionStatusMessage : Connected Version : 2023.4.1.2030 RegisteredOn : 7/19/2024 3:39:48 PM Node : Cosmos.Solarwinds.Node #> [Cmdletbinding()] [OutputType([Parmis.Solarwinds.Agent])] Param ( [Parameter(Mandatory = $true)] $Object ) Write-Verbose -Message "Converting to target object ..." $output = [Parmis.Solarwinds.Agent]::new() $output.Id = $Object.AgentId $output.Guid = $Object.AgentGuid $output.Name = $Object.HostName $output.PollingEngineId = $Object.PollingEngineId $output.AgentStatus = $Object.AgentStatus $output.AgentStatusMessage = $Object.AgentStatusMessage $output.ConnectionStatus = $Object.ConnectionStatus $output.ConnectionStatusMessage = $Object.ConnectionStatusMessage $output.Version = $Object.AgentVersion $output.RegisteredOn = $Object.RegisteredOn if ($Object.NodeId -is [System.DBNull] -or $Object.NodeId -eq "" ){ $output.Node = $null } else{ $node = Get-SwNode -InfoServiceProxy $InfoServiceProxy -Id $Object.NodeId if ($null -ne $node){ $output.Node = $node } else{ $output.Node = $null } } return $output } |