GCE Windows启动脚本 [英] GCE Windows startup script
问题描述
我遇到一个奇怪的问题,即我的 windows-startup-script-ps1
在启动时没有按照
I am facing a strange problem where my windows-startup-script-ps1
is not running at startup as per official link. This corresponds to a PowerShell script as the name indicates. Having looked further into Serial Port logs I found that the error is:
术语'gs://mybucket/metadata.ps1'不被识别为cmdlet,函数,脚本文件或可运行程序的名称.检查名称的拼写,或者是否包含路径,请验证路径正确,然后重试.
The term 'gs://mybucket/metadata.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
我尝试给它提供Cloud Storage API对象路径,但仍然出现此错误.我的Compute Engine VM具有只读的Cloud Storage访问权限,我通过在Compute Engine VM中运行 gsutil
进行了验证.谁能阐明这个问题?
I tried giving it the Cloud Storage API object path but it's still getting this error. My Compute Engine VM has read-only Cloud Storage access and I verified it by running gsutil
inside my Compute Engine VM. Can anyone shed some light on this issue?
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 ("STARTING GCE Startup Script")
$IsInstalled = ((Get-WindowsFeature -Name Web-Server).installed)
if ($isinstalled -eq $false){
Install-WindowsFeature Web-Server -IncludeManagementTools -IncludeAllSubFeature -Confirm:$false
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ASPNET45
Write-SerialPort ("Installation Complete")
}
else{
Write-SerialPort ("IIS Server (WebServer) is already installed")
}
Write-SerialPort ("FINISHING GCE Startup Script")
推荐答案
From what I could test on my end, it looks like you're adding the Cloud Storage path for the PowerShell script in the windows-startup-script-ps1 metadata key, which is meant for local startup scripts that have previously been added to the VM's image, instead of the windows-startup-script-url key that supports GCS objects:
$ gcloud计算实例创建your-windows-instance --scopes storage-ro --metadata windows-startup-script- url = gs://mybucket/metadata.ps1
$ gcloud compute instances create your-windows-instance --scopes storage-ro --metadata windows-startup-script-url=gs://mybucket/metadata.ps1
这篇关于GCE Windows启动脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!