solarwinds / OrionSDK

SDK for the SolarWinds Orion platform, including tools, documentation, and samples in PowerShell, C#, Go, Perl, and Java.
https://thwack.com/OrionSDK
Apache License 2.0
394 stars 139 forks source link

Feature Request: Copy Query As / Invoke-WebRequest (PowerShell 7+) #335

Open kmsigma opened 1 year ago

kmsigma commented 1 year ago

Although I almost always use the SwisPowerShell module, there's always a chance that I'll encounter a system where it cannot be installed. As a workaround, can we add an option to use the native Invoke-RestMethod PowerShell function as opposed to the Get-SwisData function from the SwisPowerShell module?

Syntax construction would be roughly like this:

$Uri =  'https://solarwinds.domain.local:17778//SolarWinds/InformationService/v3/Json/Query?query='
$Uri += [System.Web.HttpUtility]::UrlEncode($Query)
$Output = 'Invoke-RestMethod -Uri " + $Uri + '" -Authentication Basic -Method Get -SkipCertificateCheck -Credential ( New-Object System.Management.Automation.PSCredential -ArgumentList ( "' + $Username + '", ( "' + $Password + '" | ConvertTo-SecureString -AsPlainText ) ) )'
$Output | Set-Clipboard

What's copied to clipboard: Invoke-RestMethod -Uri 'https://solarwinds.domain.local:17778/SolarWinds/InformationService/v3/Json/Query?query=SELECT+TOP+10+Caption+%2c+IP+%2c+CONCAT(Caption%2c%27%22%2f%22%27%2cIP)+AS+%5bComboName%5d+%2c+GETUTCDATE()+AS+%5bRightNow%5d+FROM+Orion.Nodes+WHERE+IP+LIKE+%27192.168.%25.%25%27' -Authentication Basic -Method Get -SkipCertificateCheck -Credential ( New-Object System.Management.Automation.PSCredential -ArgumentList ( "MyUsername", ( "MyC0mpl3xP@ssw0rd" | ConvertTo-SecureString -AsPlainText ) ) )