【发布时间】:2017-09-02 02:34:47
【问题描述】:
我是 Powershell Runbook 的新手,如果我遗漏了一些明显的东西,请原谅我。我正在尝试从我的脚本中记录一个 Application Insights 请求,但我什至无法加载 DLL,尽管我已经看到了其他类似的代码。请注意,这是 Powershell Runbook,而不是 Powershell Workflow Runbook。
这是我的代码:
Write-Output "Starting"
$assemblyPath = "C:\Modules\Global\Azure\Compute\Microsoft.ApplicationInsights.dll"
dir $assemblyPath
Write-Output "1"
[System.Reflection.Assembly]::LoadFrom($assemblyPath)
Write-Output "2"
这是我在测试窗格中运行它时得到的输出:
Starting
Directory: C:\Modules\Global\Azure\Compute
Mode LastWriteTime Length Name
---- ------------- ------ ----
------ 1/11/2016 1:59 PM 152824 Microsoft.ApplicationInsights.dll
1
Starting
Directory: C:\Modules\Global\Azure\Compute
Mode LastWriteTime Length Name
---- ------------- ------ ----
------ 1/11/2016 1:59 PM 152824 Microsoft.ApplicationInsights.dll
1
Starting
Directory: C:\Modules\Global\Azure\Compute
Mode LastWriteTime Length Name
---- ------------- ------ ----
------ 1/11/2016 1:59 PM 152824 Microsoft.ApplicationInsights.dll
1
它似乎已经到了 LoadAssembly,然后就废话了,在放弃之前运行了 3 次脚本。任何想法我做错了什么? DLL 显然存在于该位置,并且我没有收到任何错误输出来帮助我进行调试。谢谢!
【问题讨论】:
-
@BenH 感谢您的回复,我实际上看过那篇文章,我应该提到我也尝试过该路径,但该程序集甚至不存在:dir:找不到路径 'C:\Modules\Azure\Microsoft.ApplicationInsights.dll' 因为它不存在。
-
我能够通过切换到 Powershell Runbook 并将我的所有 .NET 调用包含在 InlineScript 块中来解决我的问题。不是最优雅的,但它有效。仍然很想听听是否有办法让这个工作而不必这样做
-
好吧,试试 try-catch 并输出错误?
-
@4c74356b41 不幸的是,这无济于事。如果我确实遇到异常,例如 FileNotFound 如果我将错误的路径传递给 LoadAssembly,它会显示它,这似乎完全是另外一回事
标签: powershell azure azure-automation runbook