Skip to content

Instantly share code, notes, and snippets.

@sherzodinaev
Created February 23, 2018 01:47
Show Gist options
  • Save sherzodinaev/79fea4ff5ed2cf3aa70dbb5371c7f5df to your computer and use it in GitHub Desktop.
Save sherzodinaev/79fea4ff5ed2cf3aa70dbb5371c7f5df to your computer and use it in GitHub Desktop.
Set Windows hostname via SSM
---
schemaVersion: '2.2'
description: Sets computer name for computer(s) that is(are) part of the domain, using the value of Name tag for the selected resource(s).
mainSteps:
- action: aws:runPowerShellScript
name: setComputerNameFromTag
precondition:
StringEquals:
- platformType
- Windows
inputs:
runCommand: [
'$ComputerName=(Get-EC2Tag -Filter @{ Name="resource-id";Values="$(Invoke-RestMethod -uri http://169.254.169.254/latest/meta-data/instance-id)"},@{ Name="key";Values="Name" })[0].Value',
'$Username = "Admin"',
'$Secret = "Foo"',
'$Password = (Get-SSMParameterValue -Name $Secret -WithDecryption $True).Parameters[0].Value | ConvertTo-SecureString -AsPlainText -Force',
'$Creds = New-Object System.Management.Automation.PSCredential($Username ,$Password)',
'Rename-Computer -NewName $ComputerName -ComputerName (hostname) -Restart -DomainCredential $Creds'
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment