Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save epankur/e1d8d6e7fbc2d38df42c98b19900da24 to your computer and use it in GitHub Desktop.

Select an option

Save epankur/e1d8d6e7fbc2d38df42c98b19900da24 to your computer and use it in GitHub Desktop.

Revisions

  1. @sherzodinaev sherzodinaev created this gist Feb 23, 2018.
    19 changes: 19 additions & 0 deletions set-hostname-windows-ssm.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    ---
    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'
    ]