Hi All,
To identify components that have not been NOT UP for 180 days and delete them from the node level, first I have generated the following SWQL query, which produces the expected result when executed via SWQL Studio:
select c.ComponentID ,c.DetailsUrl ,cst.Timestamp from orion.nodes n join orion.apm.Application a on a.nodeid=n.nodeid left join orion.apm.Component c on c.ApplicationID = a.ApplicationID left join Orion.APM.CurrentComponentStatus cst on cst.ComponentID=c.ComponentID WHERE daydiff(cst.Timestamp ,getdate())> 180 ORDER by cst.Timestamp ASC
I then incorporated the same code into PowerShell to save the results into a file, so as a next step I can use that data to delete components based on url or ComponentID:
Import-Module SwisPowerShell $OrionServer = 'X.X.X.X' $Username = 'XXXX' $Password = 'XXXX' $swis = Connect-Swis -Hostname $OrionServer -Username $Username -Password $Password $query = "select c.ComponentID ,c.DetailsUrl ,cst.Timestamp from orion.nodes n join orion.apm.Application a on a.nodeid=n.nodeid left join orion.apm.Component c on c.ApplicationID = a.ApplicationID left join Orion.APM.CurrentComponentStatus cst on cst.ComponentID=c.ComponentID WHERE daydiff(cst.Timestamp ,getdate())> 180 ORDER by cst.Timestamp ASC" $results = Get-SwisData $swis $query $results | Export-CSV -Path D:\Temp\Output.txt -NoTypeInformation
But the result returns an empty output. Any idea what the issue might be with the PowerShell code?
And another thing, is it possible to use the following command to delete the component from the node level?
Remove-SwisObject $swis -Uri 'swis://localhost/Orion/View.aspx?NetObject=AM:57092'
Thanks!