Device Renaming with PowerShell API

Device Renaming with PowerShell API

I have been reading through these forums and finding a lot of help regarding API request. So far I'm able to request my API token via PS and use it for device management!  

I'm fairly new to using API calls in PS and I can't seem to get around renaming a device.  I' almost certain the issue is with how I'm using the -Body portion of the PS code. 

Here is what I have so far:

 

#ALLOWS USER INPUT OF DEVICE NAME

[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')

$title = 'Device Rename'
$msg = 'Enter New Device Name:'
$Input = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)

 

$Header2 = @{}
$Header2["Authorization"] = "Bearer " + $Token

 

try
{
$response2 = Invoke-restmethod -ContentType "application/json" -Uri https://$MCFQDN/mobicontrol/api/devices/$DevID/actions -Method POST -Headers $Header2 -Body {\"Action\": \"Rename\",\"Name\" : \"$Input\"}


}
catch
{
$($_.Exception.Message)
}

 

As stated, I think the -Body section is where I'm failing, not sure how to convert the curl request to a body in PowerShell.

 

Greatly appreciate any help!

3 Answers

Order By:   Standard | Newest | Votes
Scott | posted this 28 February 2020

Probably easier to determine if you include the code and content of the server response.

  • 0
  • 0
Jeff Burns | posted this 28 February 2020

Sorry, I never updated this.  I was able to get the correct body using the following: 


$Body2 = "{`"Action`": `"Rename`",`"Name`" : `"$Input`"}"

 

Works like a charm!

  • 0
  • 0
DDMOD@SOTI | posted this 05 March 2020

Hi Jeff Burns,

 

Thank you for requesting an answer from SOTI.

Can you please confirm if the above code works for you to rename the device?

 

Technical Support | SOTI Inc. |1.905.624.9828 | support@soti.net | www.soti.net |

  • 0
  • 0

Give us your feedback
Give us your feedback
Feedback