我有一个要求,我想将一些指标写入应用程序洞察力,以便定期监控服务。
我认为我会编写这个 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)"
谢谢西拉杰