【问题标题】:Rename ec2 hostname using userdata does not work使用用户数据重命名 ec2 主机名不起作用
【发布时间】:2022-01-11 18:20:09
【问题描述】:

我正在尝试将主机名重命名为特定的主机名 - TEAM-CNTNR 使用用户数据脚本,但在 EC2 实例上线并连接到它(通过会话管理器)后,主机名是随机的EC2服务给出EC2AMAZ-VHAGRNV等实例。

这是我的用户数据脚本,我错过了什么吗?这是我的用户数据脚本:

<powershell>
Import-Module ECSTools

[Environment]::SetEnvironmentVariable("ECS_ENABLE_AWSLOGS_EXECUTIONROLE_OVERRIDE", $TRUE, "Machine")
Initialize-ECSAgent -Cluster "${cluster_name}" -EnableTaskIAMRole -LoggingDrivers '["json-file","awslogs"]' -EnableTaskENI

# rename the instance hostname so that it works with the gMSA account
Rename-Computer -NewName "TEAM-CNTNR" -Force

## instance-domain-join code here. Omitted for brevity

# Perform the domain join
Add-Computer -DomainName "$domain_name.$domain_tld" -OUPath "OU=Computers,OU=enrcloud,DC=enr,DC=cloud" -ComputerName "$hostname" -Credential $credential -Passthru -Verbose -Restart
</powershell>
<runAsLocalSystem>true</runAsLocalSystem>

【问题讨论】:

  • VM 是否已加入域?计算机帐户是否已经存在?
  • 嗨,是的 - 在我添加主机名更改代码行之前,域加入代码运行良好

标签: amazon-web-services powershell amazon-ec2


【解决方案1】:

我发现有一个NewName 参数可以使用,它是Add-Computer 命令的一部分:

  • 将机器加入新域
  • 同时改名
Add-Computer ... -NewName "MyComputer" ...

参考:Microsoft site

【讨论】:

    猜你喜欢
    • 2011-07-13
    • 1970-01-01
    • 2015-06-20
    • 1970-01-01
    • 2015-12-31
    • 1970-01-01
    • 2018-03-11
    • 2018-02-08
    相关资源
    最近更新 更多