Anyone have a powershell script that deletes a computer using powershell?
I see..
You should post your concerns with that topic to that topic. I might take a look at that some day.
Here is the script that I am using. Everything works with the exception of deleting an exsisting device.
Also try to find how to pass the "Customer Name" and "Y" when prompted to delete the devide within the script, not as a PS switch.
https://community.teamviewer.com/t5/TeamViewer-General/PowerShell-Based-Host-Deployment-msi/m-p/14151#M7840
Thank you Kentain,
I have a script that was posted elsewhere but never got it to work with delete device in the TeamViewer portal. So I was trying your script to see if I could resolve my issue.
# Check to see if device already exists, prompt to delete it if it does$devices = Invoke-RestMethod -Uri "$base_url/api/v1/devices" -Headers $headers$existing_device = $devices.devices | where { $_.alias -eq $device_alias }if ($existing_device) {$title = "Delete Device"$message = "A device with the name $device_alias already exists. Do you wish to delete it?"
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", `"Deletes the device $device_alias."
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", `"Cancels the current installation."
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$result = $host.ui.PromptForChoice($title, $message, $options, 0)
switch ($result) {0 {try {Invoke-RestMethod -Method Delete `-Uri "$base_url/api/v1/devices/$($existing_device.device_id)" `-Headers $headers}catch {throw "Error deleting device"}}1 {throw "Device already exists"}}}
However, when I run this I get the following error;
Error deleting deviceAt C:\temp\DTV12.ps1:45 char:17+ throw "Error deleting device"+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo : OperationStopped: (Error deleting device:String) [], RuntimeException+ FullyQualifiedErrorId : Error deleting device
Line 45 Char: 17 is refering to "throw "Error deleting device"" in my script.
Any thougts?
The script works, either you are doing it wrong or the site was unavailable, i get 204's.For dID you probably put in the contact ID, complete with spaces, and not the actual device ID.To get the dIDs, you can do something like this:$thing = Invoke-WebRequest -Uri "https://webapi.teamviewer.com/api/v1/devices/" -Method get -Headers $headerConvertFrom-Json ($thing) | Select-Object -expand devices | ConvertTo-Csv -NoTypeInformation
This script does not work. Fails with "Invalid URI".
Should be something like:$computer = "put the dID here"$token = "Paste your api token here"
$bearer = "Bearer", $token$header = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"$header.Add("authorization",$bearer)
Invoke-WebRequest -Uri "https://webapi.teamviewer.com/api/v1/devices/$computer" -Method Delete -Headers $header