GCE Windows实例未运行启动脚本

时间:2015-01-23 22:29:22

标签: powershell windows-server-2008-r2 google-compute-engine gcloud

我一直在尝试将我的启动脚本应用到Google Compute Engine上的新Windows实例,如here所述,但是当我检查实例时,没有任何痕迹被执行过。这是我正在运行的gcloud命令:

gcloud compute instances create" my-instance" --project" my-project"
--zone" us-central1-a"
- 机器类型" g1-small"
- 网络"默认"
--metadata" gce-initial-windows-user = my-user" " GCE-初始 - 窗口密码=我的通"
- 维护政策" MIGRATE"
--scopes" storage-ro" --tags" http-server" " HTTPS服务器"
--image" https://www.googleapis.com/compute/v1/projects/windows-cloud/global/images/windows-server-2008-r2-dc-v20150110"
--boot-disk-type" pd-standard"
--boot-disk-device-name" my-instance"
--metadata-from-file sysprep-oobe-script-ps1 = D:\ Path \ To \ startup.ps1

我尝试使用所有3种启动类型(sysprep-specialize-script-ps1,sysprep-oobe-script-ps1,windows-startup-script-ps1),但都没有用。无法在任务计划程序或事件查看器中看到任何指示。我的系统上的文件存在,并且在我手动运行时可以正常工作。我怎样才能使这个工作?

2 个答案:

答案 0 :(得分:1)

调试Powershell脚本的一个好方法是让它们写入串行控制台(COM1)。您将能够从GCE的串行端口输出中看到脚本的输出。

  

gcloud compute instances get-serial-port-output my-instance --zone   US-central1-A

如果没有脚本,你会看到类似的内容:

Calling oobe-script from metadata.
attributes/sysprep-oobe-script-bat value is not set or metadata server is not reachable.
attributes/sysprep-oobe-script-cmd value is not set or metadata server is not reachable.
attributes/sysprep-oobe-script-ps1 value is not set or metadata server is not reachable.
Running schtasks with arguments /run /tn GCEStartup
-->  SUCCESS: Attempted to run the scheduled task "GCEStartup".
-------------------------------------------------------------
Instance setup finished. windows is ready to use.
-------------------------------------------------------------
Booting on date 01/25/2015 06:26:26
attributes/windows-startup-script-bat value is not set or metadata server is not reachable.
attributes/windows-startup-script-cmd value is not set or metadata server is not reachable.
attributes/windows-startup-script-ps1 value is not set or metadata server is not reachable.

确保ps1文件的内容实际附加到实例。

  

gcloud计算实例描述my-instance --zone us-central1-a   --format json

JSON转储应该包含powershell脚本。

最后,调试Powershell启动脚本的一个好方法是将输出写入串行控制台。

您可以在Google Developer Console中打印日志消息并查看它们>计算>计算引擎> VM实例> (实例名称)。然后滚动到底部并单击“串行控制台”的展开选项。

Function Write-SerialPort ([string] $message) {
    $port = new-Object System.IO.Ports.SerialPort COM1,9600,None,8,one
    $port.open()
    $port.WriteLine($message)
    $port.Close()
}

Write-SerialPort ("Testing GCE Startup Script")

这个命令对我有用,我必须确保脚本是用ascii编写的。 Powershell ISE使用不同的编码来破坏gcloud compute。

  

gcloud compute instances创建testwin2 --zone us-central1-a   --metadata-from-file sysprep-oobe-script-ps1 = testconsole.ps1 --image windows-2008-r2

答案 1 :(得分:0)

我在我的powershell启动脚本中尝试了Write-SerialPort功能,但它显示无法打开或无法每次关闭。

所以我尝试写输出它可以工作。

相关问题