【发布时间】:2015-12-31 20:20:45
【问题描述】:
更新:我按照 BenV 的以下建议使用了 Azure 自动化,它成功了!更多信息可以找到here。
我有一个 PowerShell 脚本,它需要运行一些 Azure 命令,例如 New-AzureStorageContext、Get-AzureStorageContainer、Set-AzureStorageBlobContent 等。我想将该脚本作为网络作业运行。
当我将此脚本作为 Web 作业运行时,我在 Azure 命令中收到以下错误。其他 PS 命令从 webjob 成功运行。
我搜索了 StackOverflow,但找不到有关从 Web 作业运行 Azure 命令时生成的这些错误的帖子。提到使用Import-Module 的一些相关帖子类似于下面给出的建议。
一篇较早的 MSDN 博文建议在 PS 脚本中添加“Import-Module Azure.ps1”,并将 Azure.ps1 包含在 webjob zip 文件中。 (它实际上是来自我本地 C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure 的 Azure.psd1)。另外,我尝试了使用 Azure.psd1 的 Import-Module 然后 Azure.ps1 认为错误可能与文件扩展名有关,但事实并非如此。
我的 webjob .zip 文件只有我的 .CMD 文件 GetLinks.ps1 和 Azure.ps1。
我的 .CMD 文件使用以下命令启动我的 PS 脚本:PowerShell.exe -ExecutionPolicy RemoteSigned -File GetLinks.ps1
在这个 .ps1 文件的顶部,我有:“Import-Module .\Azure.ps1”。这运行成功,因为我在我的 WebJob 运行日志中看到“INFO”语句。
接下来,我的 PS 脚本尝试运行 Azure PS 命令,但我仍然遇到与下面的一个示例错误相同的错误。
New-AzureStorageContext : The term 'New-AzureStorageContext' 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.
At D:\local\Temp\jobs\triggered\getlinks2\b2025qk5.ddj\GetLinks.ps1:75 char:19
+ $storageContext = New-AzureStorageContext -StorageAccountName $storageAccountNam ...
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (New-AzureStorageContext:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
【问题讨论】:
-
促使您使用 WebJobs 的要求是什么?有什么理由不能使用Azure Automation?
-
谢谢。我将研究 Azure 自动化。另一种选择是按照 David 下面的建议编写 C# 应用程序。
标签: powershell azure azure-webjobs