AWS/Set Host Name
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
- 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