PS – Rename computer variable not working

I am working on a script to rename host-name in aws. Right now I have the value output to a variable. When I run the command I get an error below. When I show the variable typing $hostname it has a value

Rename-Computer : Cannot validate argument on parameter ‘NewName’. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

$instanceId = (Invoke-RestMethod -Method Get -Uri
$hostname = ((Get-EC2Instance -InstanceId $instanceId).instances.tag.value)
Rename-Computer -NewName “$hotsname”

submitted by /u/chappys4life
[link] [comments]

Leave a Reply