GCE Windows 启动脚本 [英] GCE Windows startup script
问题描述
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:
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.
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 compute instances create your-windows-instance --scopes storage-ro --metadata windows-startup-script-url=gs://mybucket/metadata.ps1
这篇关于GCE Windows 启动脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!