我有这样的需求,我想把一些指标写到应用程序洞察力中,以便定期监控服务。
我认为我应该编写这个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)"谢谢Siraj
发布于 2016-05-06 03:26:36
尝试遵循程序集"C:\Modules\Global\Azure\Compute\Microsoft.ApplicationInsights.dll“的路径
发布于 2016-05-06 04:55:45
加载DLL文件时出现问题。Runbook找不到以下行中的文件:
$AI = "$PSScriptRoot\Microsoft.ApplicationInsights.dll"
[Reflection.Assembly]::LoadFile("$AI")当你通过Azure Automation运行Runbook时,你无法像通常在本地计算机或内部部署那样访问本地路径。在Azure Automation中,模块被放在"C:\ modules “中。
相反,在上传dll文件之后,请使用以下代码片段:
[System.Reflection.Assembly]::LoadFrom("C:\Modules\Azure\Microsoft.ApplicationInsights.dll")最相关的参考资料:Referencing DLL
https://stackoverflow.com/questions/35870749
复制相似问题