From 1da03d1c149abb12640b26a3adc2cb91492d649c Mon Sep 17 00:00:00 2001 From: adamwojcik Date: Wed, 14 Oct 2020 12:37:03 +0200 Subject: [PATCH] Added powershell example for discovering wmi node --- Samples/PowerShell/DiscoverWmiNode.ps1 | 102 +++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 Samples/PowerShell/DiscoverWmiNode.ps1 diff --git a/Samples/PowerShell/DiscoverWmiNode.ps1 b/Samples/PowerShell/DiscoverWmiNode.ps1 new file mode 100644 index 000000000..db2b0430f --- /dev/null +++ b/Samples/PowerShell/DiscoverWmiNode.ps1 @@ -0,0 +1,102 @@ +# This sample script shows how to use the Orion Discovery API to discover and import one node using SNMPv3 credentials. + +# Load SwisPowerShell +Import-Module SwisPowerShell + +# Swis connection info +$OrionServer = "localhost" +$Username = "admin" +$Password = "" + +# Discovery parameters +$ip = "10.199.4.3" +$wmiCredentialsName = 'admin' +$engindId = 1 +$DeleteProfileAfterDiscoveryCompletes = "true" + +$swis = Connect-Swis $OrionServer -UserName $Username -Password $Password + +# Get the ID of the named SNMPv3 credential +$wmiCredentialsId= Get-SwisData $swis "SELECT ID FROM Orion.Credential WHERE Name=@name" @{name = $wmiCredentialsName} + +$CorePluginConfigurationContext = ([xml]" + + + +
$ip
+
+
+ + + $wmiCredentialsId + 1 + + + 1 + 1000 +
+").DocumentElement + +$CorePluginConfiguration = Invoke-SwisVerb $swis Orion.Discovery CreateCorePluginConfiguration @($CorePluginConfigurationContext) + +$StartDiscoveryContext = ([xml]" + + Script Discovery $([DateTime]::Now) + $engindId + 3600 + 2000 + 2000 + 1 + 1500 + 161 + 0 + SNMP2c + false + false + true + $DeleteProfileAfterDiscoveryCompletes + 1 + + + $($CorePluginConfiguration.InnerXml) + + + +").DocumentElement + +$DiscoveryProfileID = (Invoke-SwisVerb $swis Orion.Discovery StartDiscovery @($StartDiscoveryContext)).InnerText + +Write-Host -NoNewline "Discovery profile #$DiscoveryProfileID running..." + +# Wait until the discovery completes +do { + Write-Host -NoNewline "." + Start-Sleep -Seconds 1 + $Status = Get-SwisData $swis "SELECT Status FROM Orion.DiscoveryProfiles WHERE ProfileID = @profileId" @{profileId = $DiscoveryProfileID} +} while ($Status -eq 1) + +# If $DeleteProfileAfterDiscoveryCompletes is true, then the profile will be gone at this point, but we can still get the result from Orion.DiscoveryLogs + +$Result = Get-SwisData $swis "SELECT Result, ResultDescription, ErrorMessage, BatchID FROM Orion.DiscoveryLogs WHERE ProfileID = @profileId" @{profileId = $DiscoveryProfileID} + +# Print the outcome +switch ($Result.Result) { + 0 {"Unknown"} + 1 {"InProgress"} + 2 {"Finished"} + 3 {"Error"} + 4 {"NotScheduled"} + 5 {"Scheduled"} + 6 {"NotCompleted"} + 7 {"Canceling"} + 8 {"ReadyForImport"} +} +$Result.ResultDescription +$Result.ErrorMessage + +if ($Result.Result -eq 2) { # if discovery completed successfully + # Find out what objects were discovered + $Discovered = Get-SwisData $swis "SELECT EntityType, DisplayName, NetObjectID FROM Orion.DiscoveryLogItems WHERE BatchID = @batchId" @{batchId = $Result.BatchID} + "$($Discovered.Count) items imported." + $Discovered +} \ No newline at end of file