Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 什么是PowerShell.Telemetry.ApplicationInsightsTelemetry?我可以关闭它吗?_C#_Powershell_.net Core_.net Core 3.1 - Fatal编程技术网

C# 什么是PowerShell.Telemetry.ApplicationInsightsTelemetry?我可以关闭它吗?

C# 什么是PowerShell.Telemetry.ApplicationInsightsTelemetry?我可以关闭它吗?,c#,powershell,.net-core,.net-core-3.1,C#,Powershell,.net Core,.net Core 3.1,我有一个C#测试项目,它使用Microsoft.PowerShell.SDKNuGet包。我使用它来运行cURL命令,而我似乎无法使用HttpClient(如果您感兴趣,请详细说明) 它工作得很好,除非我使用RunImpersonated以弱用户身份运行。然后我得到以下异常: System.TypeInitializationException:“Microsoft.PowerShell.Telemetry.ApplicationInsightsTelemetry”的类型初始值设定项引发异常 内

我有一个C#测试项目,它使用
Microsoft.PowerShell.SDK
NuGet包。我使用它来运行cURL命令,而我似乎无法使用
HttpClient
(如果您感兴趣,请详细说明)

它工作得很好,除非我使用
RunImpersonated
以弱用户身份运行。然后我得到以下异常:

System.TypeInitializationException:“Microsoft.PowerShell.Telemetry.ApplicationInsightsTelemetry”的类型初始值设定项引发异常

内部例外情况如下:

System.UnauthorizedAccessException:对路径“CreateUniqueUserId”的访问被拒绝

我不知道为什么我的cURL powershell命令需要使用Application Insights,如果可能的话,我想将其关闭

是否可以通过Powershell NuGet关闭应用程序洞察功能?从以下位置:

要选择退出此遥测,请将环境变量
POWERSHELL\u telemetry\u OPTOUT
设置为true、yes或1

因此,在应用程序启动时运行此功能应该可以做到:

Environment.SetEnvironmentVariable("POWERSHELL_TELEMETRY_OPTOUT", "1");

明亮的非常感谢。