From 06c9340e8631cfadc4bbf9ea6476e395b77f2491 Mon Sep 17 00:00:00 2001 From: Brian Wuchner Date: Tue, 12 May 2020 08:08:20 -0400 Subject: [PATCH 1/2] Update LogInsight.psm1 Update line 54 so function Convert-hLogInsightTimeField can deal with data returned from the agent API call. Add rows 336 to 366 for function Get-LogInsightAgent to return a list of Log Insight agents. --- LogInsight.psm1 | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/LogInsight.psm1 b/LogInsight.psm1 index 22e3e15..c44d3b4 100644 --- a/LogInsight.psm1 +++ b/LogInsight.psm1 @@ -45,13 +45,13 @@ function Convert-hLogInsightTimeField Write-Verbose -Message "`tCalled from $($stack = Get-PSCallStack; $stack[1].Command) at $($stack[1].Location)" foreach($obj in $Object) - { + { $obj.psobject.properties | ForEach-Object -Process { if('System.Object[]','System.Management.Automation.PSCustomObject' -contains $_.TypeNameOfValue) { Convert-hLogInsightTimeField -Object $obj.$($_.Name) } - elseif($_.Name -match 'Time' -and $_.TypeNameOfValue -eq 'System.Int64') + elseif($_.Name -match 'Time|lastSeen|statsAsOf' -and $_.TypeNameOfValue -eq 'System.Int64') { $obj.$($_.Name) = (ConvertFrom-hLogInsightJsonDateTime -DateTime $obj.$($_.Name)) } @@ -331,4 +331,36 @@ function Get-LogInsightConstraint return $ExecutionContext.InvokeCommand.ExpandString($convertTab[$Operator]) } -} \ No newline at end of file +} + +function Get-LogInsightAgent +{ + [CmdletBinding(SupportsShouldProcess = $True, ConfirmImpact = 'Low')] + param ( + [Switch]$Raw + ) + + Process + { + Write-Verbose -Message "$($MyInvocation.MyCommand.Name)" + Write-Verbose -Message "`t$($PSCmdlet.ParameterSetName)" + Write-Verbose -Message "`tCalled from $($stack = Get-PSCallStack; $stack[1].Command) at $($stack[1].Location)" + + $sAgent = @{ + Method = 'Get' + Request = 'agent' + } + + If ($PSCmdlet.ShouldProcess('Connecting to Log Insight')) + { + $agents = Invoke-hLogInsightRest @sAgent + + if (!$Raw) + { + Convert-hLogInsightTimeField -Object $agents + } + + $agents.agents + } + } +} From 39aa8f24846531d39e0cadb73a2649b99a6d6ac5 Mon Sep 17 00:00:00 2001 From: Brian Wuchner Date: Tue, 12 May 2020 08:09:52 -0400 Subject: [PATCH 2/2] Create Query-Agents.ps1 --- Examples/Query-Agents.ps1 | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Examples/Query-Agents.ps1 diff --git a/Examples/Query-Agents.ps1 b/Examples/Query-Agents.ps1 new file mode 100644 index 0000000..0be88a8 --- /dev/null +++ b/Examples/Query-Agents.ps1 @@ -0,0 +1,11 @@ +Import-Module -Name LogInsight + +$sConnect = @{ + Server = 'LogInsight.local.lab' + User = 'admin' + Password = 'VMware1!' +} + +Connect-LogInsight @sConnect + +$agents = Get-LogInsightAgent