Created
February 23, 2018 01:47
-
-
Save sherzodinaev/79fea4ff5ed2cf3aa70dbb5371c7f5df to your computer and use it in GitHub Desktop.
Revisions
-
sherzodinaev created this gist
Feb 23, 2018 .There are no files selected for viewing
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 charactersOriginal 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' ]