【问题标题】:Azure Runbook load .Net assembly for application insightAzure Runbook 加载 .Net 程序集以了解应用程序
【发布时间】:2016-06-22 14:20:28
【问题描述】:

我有一个要求,我想将一些指标写入应用程序洞察力以定期监控服务。

虽然我会编写这个 PowerShell 脚本并相应地安排它。

Write-Output "Script Start"
$PSScriptRoot = Get-Location
$AI = "$PSScriptRoot\Microsoft.ApplicationInsights.dll"
[Reflection.Assembly]::LoadFile("$AI")
$InstrumentationKey = ""
$TelClient = New-Object "Microsoft.ApplicationInsights.TelemetryClient"
$TelClient.InstrumentationKey = $InstrumentationKey

$TrackMetric = New-Object "Microsoft.ApplicationInsights.DataContracts.MetricTelemetry"
$TrackMetric.Name = "PowershellTest"
$TrackMetric.Value = Get-Random -Minimum:1 -Maximum:100

$TelClient.TrackMetric($TrackMetric)
$TelClient.Flush()

Write-Output "Script End  $TrackMetric.Value"

此 PowerShell 脚本有效,但在我将该脚本移至 Runbook 后,它不再有效。

所以,这就是问题所在。 我无法在 Runbook 中加载 ApplicationInsight DLL。

知道怎么做吗?

异常详情

Exception calling "LoadFile" with "1" argument(s): "The system cannot find the file specified. (Exception from HRESULT: 
0x80070002)"

谢谢 西拉杰

【问题讨论】:

  • 请在尝试从Runbook 运行此代码时发布您收到的实际错误代码。

标签: powershell azure automation runbook


【解决方案1】:

尝试以下程序集路径 "C:\Modules\Global\Azure\Compute\Microsoft.ApplicationInsights.dll"

【讨论】:

    【解决方案2】:

    问题在于加载 DLL 文件。 Runbook 在此行中找不到文件:

    $AI = "$PSScriptRoot\Microsoft.ApplicationInsights.dll"
    [Reflection.Assembly]::LoadFile("$AI")
    

    当您通过 Azure 自动化运行 Runbook 时,您无法像通常在本地计算机或本地那样访问本地路径。在 Azure 自动化中,模块放置在“C:\Modules”中。

    在您上传 dll 文件后,请使用以下代码 sn-p:

    [System.Reflection.Assembly]::LoadFrom("C:\Modules\Azure\Microsoft.ApplicationInsights.dll")
    

    最近的相关参考:Referencing DLL

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-05
    • 2012-10-15
    • 1970-01-01
    • 1970-01-01
    • 2021-05-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多