Forked from sherzodinaev/set-hostname-windows-ssm.yaml
Created
October 31, 2022 19:55
-
-
Save epankur/e1d8d6e7fbc2d38df42c98b19900da24 to your computer and use it in GitHub Desktop.
Set Windows hostname via SSM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| 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