GCE Windows startup script

旧城冷巷雨未停 提交于 2021-01-20 12:26:35

问题


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")

回答1:


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



来源:https://stackoverflow.com/questions/65342169/gce-windows-startup-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!