Powershell to reassign with new name

andreglud
andreglud Posts: 1
edited February 5 in Deployment & Integrations

Hi there,

Can anyone suggest a way to reenroll machines with a new name in Powershell? The script I've been tinkering with doesn't seem to work as names are never updated.

$deviceName = (Get-WmiObject -Class Win32_ComputerSystem).Name
$compuser = "$deviceName|$env:username"
# Write-Host "CompUser: $compuser"
Start-Process -FilePath "C:\Program Files (x86)\TeamViewer\TeamViewer.exe" -ArgumentList "--reassign --api-token=XXXXXXXX-XXXXXXXXXXXXXXXXXXXX --grant-easy-access --alias %compuser%"

I was hoping we could use this script when computers switch hands and a new user is taking primary control of the device.