![](/img/trans.png)
[英]Azure Error: SubscriptionNotAuthorizedForImage when deploying a Visual Studio Community VM from Azure Marketplace
[英]How to run PowerShell cmdlets from custom PS modules when deploying a new Azure VM?
是否可以在 Azure VM 部署后任务中安装自定义 PowerShell 模块并在此任务中从该模块运行 PS cmdlet?
我有一个部署新 Windows Azure VM 的 Bicep 模板。 该模板有一个Microsoft.Compute/virtualMachines/extensions@2020-12-01
部署后资源,它执行以下步骤:
Start-Process
(OK) 安装 MSI 打包的应用程序(带有新的自定义 PowerShell 模块)从部署后脚本中的自定义模块运行 cmdlet 会在“Extensions + applications”日志中显示以下错误:
... is not recognized as the name of a cmdlet...
当我将部署后步骤更改为Import-Module MODULENAME
时,我看到另一条消息:
Import-Module: The specified module 'MODULENAME' was not loaded because no valid module file was found in any module \r\ndirectory.
当我在部署后任务中运行Get-Module
时,我只看到这两个模块列表:
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Con...
Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
所以模块没有被加载。
但是,当我远程访问已部署的 VM 时,我从自定义 PowerShell 模块运行 cmdlet,没有任何错误。
我认为我的场景是受支持的,但我不太明白如何进一步解决这个问题。
我添加了-Wait
to Start-Process
,这解决了问题。
看来问题出在我的customScript.ps1
脚本上。 脚本的第一行安装了一个 MSI 打包的应用程序,它添加了所需的 PowerShell 模块:
Start-Process -FilePath msiexec.exe -ArgumentList @('/i', 'msi-installer-name.msi', '/qb')
PowerShell 使用Start-Process
开始安装并继续。 所以当我运行这些命令时,安装还没有完成:
$env:PSModulePath | Out-File C:\Temp\psmodulepath.txt
Get-Module -ListAvailable | Out-File C:\Temp\getmodulelistavailable.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.