Linux管理员拿出了我试图在GCE上找出适用于Windows的启动脚本的头发 .

我接近它的方式如下;

  • 通过编辑"master"图像上的注册表来创建"runonce"脚本 .

  • 所述脚本执行以下操作; -

  • 对其自己的IP进行反向DNS查找以获取主机名DNS认为是,然后将本地主机名设置为

  • 加入域名

  • 将域用户添加为自动登录(由于各种原因我需要这个)

  • 我GCESysprep机器

  • 在sysprep之后拍摄机器的图像并从中制作组模板

我遇到的主要问题是它根本不工作:)机器出现,运行脚本并重新启动但是上帝知道他们回来后他们处于什么状态,我无法登录,重置密码/做任何事情 .

我认为理想情况下我想要做的是找出最佳方法,我是否在GCE Storage中托管脚本并在GCE控制台中将其标记为与注册表设置相对的启动脚本?有没有更好的方法来重命名机器?

如果你感兴趣,这是剧本;

If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))

{   
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}

$ipAddresses = (get-netadapter | get-netipaddress | ? addressfamily -
eq 'IPv4').ipaddress
# Filter out any 192.168 172. 10. IP addresses
$ipAddress = $ipAddresses -like "123*"
# Retrieve the hostname from the ??? DNS Server
$fqdn = (nslookup $ipAddresses | sls name | select -last 
1).toString().split(":")[1].trim()
# We only need the hostname without the domain info so split it up
$fqdn_items = $fqdn.split(".")
$newComputerName = $fqdn_items[0]
Write-Host "New Computer Name: $newComputerName"
# Get a WMI object representing the current computer
$currentComputer = Get-WmiObject Win32_ComputerSystem
Write-Host "Attempting to change computer name to $newComputerName"
# Set the Computer Name to the hostname found via DNS Lookup to DNS 
Server
# This can only be performed before joining the domain otherwise you 
get return code 1326
$currentComputer.Rename($newComputerName)

#SET CREDENTIALS
$domain = “mydomain”
$password = “password” | ConvertTo-SecureString -asPlainText -Force
$username = "$domain\joinuser” 
$credential = New-Object 
System.Management.Automation.PSCredential($username,$password)


# RENAME THE COMPUTER
Rename-Computer -ComputerName (hostname) -NewName $newComputerName -
LocalCredential $credentiallocal

sleep 100

# JOIN THE DOMAIN
Add-Computer -DomainName $domain -Credential $credential -force 

# CONFIGURE AUTOLOGIN
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows 
NT\CurrentVersion\Winlogon' -Name AutoAdminLogon -Value 1
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows 
NT\CurrentVersion\Winlogon' -Name DefaultUserName -Value 
“mydomain\dr-worker"
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows 
NT\CurrentVersion\Winlogon' -Name DefaultPassword -Value mypassword

restart