Does anyone know if there is a PowerShell module for SolarWinds Service desk, or some kind of API we can utilize?
We are wanting to update asset objects with PowerShell every time a device group membership changes in Microsoft Intune.
should be below
https://apidoc.samanage.com/
Thanks @dodo123
This should work for what we need.
Below is an example I tested adding to a Custom Field to assets with using Powershell.
# Set to True to see debug output below. $DEBUG = $true# This is used to perform a forced refresh. Will also cause a new asset that has not yet checked in# to check in for the first time and get added to Solarwinds.$FileToVerify = "C:\Program Files (x86)\Solarwinds Discovery Agent\agent\ruby\bin\SamanageAgent.exe"If(Test-Path "$FileToVerify") { Write-Verbose "Performing SWSD Discovery Check In" $RubyEXE = "c:\Program Files (x86)\Solarwinds Discovery Agent\agent\ruby\bin\ruby.exe" $RubyARGS = @('c:\Program Files (x86)\Solarwinds Discovery Agent\agent\src\mini_kernel\cmd.rb', '-f') & $RubyEXE $rubyArgs Start-Sleep -Seconds 120}# This method takes longer and loads more information than we want.#$BasePCName = (Get-ComputerInfo).CSName# This method is very fast plus it works on MAC OS devices.$BasePCName = Invoke-Expression -Command 'hostname'# Be sure to include the trailing slash (/)$UriBase = "https://api.samanage.com/"# the API's URI that we'll be connecting to# Be sure to OMIT the initial slash (/)$Uri = "hardwares.json?name=$BasePCName"#Combine the URI components to a single string$UriGet = $UriBase + $Uri# API Token for an account.# Things could be adjusted to use User/Pass if you prefer.$JsonWebToken = 'YourSecretTokenGoesHere'# Header is always the same when doing GET, PUT, POST.$Headers = @{ "X-Samanage-Authorization" = "Bearer $JsonWebToken"; "Accept" = "application/vnd.samanage.v2.1+json" "Content-Type" = "application/json" }$Response = ""try{ $Response = Invoke-RestMethod -Uri $UriGet -Headers $Headers -Method GET} catch { # Dig into the exception to get the Response details. # We add the failed message in case statuscode and desc are blank (aka, usually an idication the site was blocked) Write-Host "Failed to verify PC Name via API" Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__ Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription Exit 1000}$PCid = $Response.idif ($DEBUG){ Write-Host "PC ID: " $PCid}if ($PCid -gt 1){ $UpdateUri = "hardwares/$PCid.json" $UriPost = $UriBase + $UpdateUri $PCUUID = (Get-CimInstance -Class Win32_ComputerSystemProduct).UUID if ($DEBUG) { Write-Host "Querying URL: " $UriPost Write-Host "UUID To Use: " $PCUUID } $UUIDBody = @" { "hardware": { "custom_fields_values": { "custom_fields_value": [{ "name" : "UUID" , "value" : "$PCUUID" }] } } } $UpdateResponse = "" try { $UpdateResponse = Invoke-RestMethod -Method Put -Headers $Headers -Uri $UriPost -Body $UUIDBody if ($UpdateResponse.id -gt 1) { Write-Host "UUID has been updated for this PC: " $BasePCName Exit 0 } } catch { # Dig into the exception to get the Response details. # Note that value__ is not a typo. Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__ Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription Exit 1000 }} else { Write-Host "PC was not found by name in SWSD: " $BasePCName Exit 1000}