AWS/Set Host Name

From Ever changing code
< AWS
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Windows

User-data

<syntaxhighlightjs lang="powershell"> Add-Computer -ComputerName $env:COMPUTERNAME -NewName (((Get-EC2Instance -Instance (Invoke-RestMethod -Method Get -Uri http://169.254.169.254/latest/meta-data/instance-id)).RunningInstance.Tags | Where-Object { $_.Key -eq "Name" }).Value) -DomainName example.com -Credential example\user -restart

  1. Require IAM-profile

Invoke-RestMethod -Method Get -Uri http://169.254.169.254/latest/meta-data/instance-id Get-EC2Instance -InstanceId i-12312312311111122

$instance = (Get-EC2Instance -InstanceId i-12312312311111122) $instance.Instances.tags </syntaxhighlightjs>


Rename using PowerShell rename <syntaxhighlightjs lang="powershell"> <powershell> Rename-Computer -NewName foo -Force Restart-Computer </powershell> </syntaxhighlightjs>

Resources