草庐IT

windows - Azure CustomScript Extension -- WindowsVM -- Restart-Computer -- 启动时触发脚本

coder 2024-06-20 原文

我很难在 Azure 机器(Windows Server 2012 R2 数据中心)上自动安装应用程序。

我的脚本分两步编写:

  • 第一步:安装.NET4.6.1然后重启完成安装
  • 第二步:安装我的应用

我无法在机器 wackup 时重新启动我的脚本。

有使用 ScheduldedTaskschtasks 的技术,但只有当我使用远程桌面登录计算机时它才会成功。当脚本由 Azure CustomScript Extension 运行时,脚本不会被安排重新启动。

目标是运行 ARM 部署,这将使用 CustomScript Extension 安装我的应用程序,而无需我执行任何操作。

这是我使用 ScheduldedTask 创建唤醒任务的代码:

$ Pstart = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
$ Actionscript = "& `"C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.4\Downloads\0\MyScript.ps1`""
$ Action = New ScheduledTaskAction -execute $ pstart -argument $ actionscript
$ Trigger = New ScheduledTaskTrigger -AtStartUp
Register-ScheduledTask `
   -TaskName $TaskName `
   -Action $Action `
   -Trigger $Trigger `
   -RunLevel Highest `
   -User "$Userdomain\$Username" `
   -password $UncryptedPassword

这是我的 schtasks 代码:

schtasks /create `
  /RU $username `
  /PR $UncryptedPassword `
  /SC ONSTART `
  /TN $taskName `
  /TR "'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' & `"C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.4\Downloads\0\MyScript.ps1`"" `
  /RL HIGHEST

这两个代码在 VM 唤醒时激活脚本,但仅当我通过远程桌面运行它时。

AzureCustomScriptExtension执行时出现错误。

最佳答案

当用户通过 RDP 连接时任务运行,这让我想到了配置文件加载。我找到了那篇知识库文章 https://support.microsoft.com/en-us/kb/2968540这可能是 Windows Server 2012 R2 中的解决方案。

关于windows - Azure CustomScript Extension -- WindowsVM -- Restart-Computer -- 启动时触发脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36986349/

有关windows - Azure CustomScript Extension -- WindowsVM -- Restart-Computer -- 启动时触发脚本的更多相关文章

随机推荐