mirror of
https://github.com/PowerShell/PowerShell
synced 2025-10-06 00:22:59 +02:00
Remove the use of Windows PowerShell ETW provider id and update PSDiagnostics
module to work for PowerShell 7 (#25590)
This commit is contained in:
@@ -4,21 +4,22 @@
|
||||
<#
|
||||
PowerShell Diagnostics Module
|
||||
This module contains a set of wrapper scripts that
|
||||
enable a user to use ETW tracing in Windows
|
||||
PowerShell.
|
||||
enable a user to use ETW tracing in PowerShell 7.
|
||||
#>
|
||||
|
||||
$script:Logman="$env:windir\system32\logman.exe"
|
||||
$script:wsmanlogfile = "$env:windir\system32\wsmtraces.log"
|
||||
$script:wsmprovfile = "$env:windir\system32\wsmtraceproviders.txt"
|
||||
$script:windir = [System.Environment]::GetEnvironmentVariable("windir", [System.EnvironmentVariableTarget]::Machine)
|
||||
|
||||
$script:Logman = "${script:windir}\system32\logman.exe"
|
||||
$script:wsmanlogfile = "${script:windir}\system32\wsmtraces.log"
|
||||
$script:wsmprovfile = "${script:windir}\system32\wsmtraceproviders.txt"
|
||||
$script:wsmsession = "wsmlog"
|
||||
$script:pssession = "PSTrace"
|
||||
$script:psprovidername="Microsoft-Windows-PowerShell"
|
||||
$script:psprovidername = "PowerShellCore"
|
||||
$script:wsmprovidername = "Microsoft-Windows-WinRM"
|
||||
$script:oplog = "/Operational"
|
||||
$script:analyticlog="/Analytic"
|
||||
$script:debuglog="/Debug"
|
||||
$script:wevtutil="$env:windir\system32\wevtutil.exe"
|
||||
$script:analyticlog = "/Analytic"
|
||||
$script:debuglog = "/Debug"
|
||||
$script:wevtutil = "${script:windir}\system32\wevtutil.exe"
|
||||
$script:slparam = "sl"
|
||||
$script:glparam = "gl"
|
||||
|
||||
@@ -169,7 +170,6 @@ function Enable-PSWSManCombinedTrace
|
||||
|
||||
$provfile = [io.path]::GetTempFilename()
|
||||
|
||||
$traceFileName = [string][Guid]::NewGuid()
|
||||
if ($DoNotOverwriteExistingTrace) {
|
||||
$fileName = [string][guid]::newguid()
|
||||
$logfile = $PSHOME + "\\Traces\\PSTrace_$fileName.etl"
|
||||
@@ -177,8 +177,8 @@ function Enable-PSWSManCombinedTrace
|
||||
$logfile = $PSHOME + "\\Traces\\PSTrace.etl"
|
||||
}
|
||||
|
||||
"Microsoft-Windows-PowerShell 0 5" | Out-File $provfile -Encoding ascii
|
||||
"Microsoft-Windows-WinRM 0 5" | Out-File $provfile -Encoding ascii -Append
|
||||
"$script:psprovidername 0 5" | Out-File $provfile -Encoding ascii
|
||||
"$script:wsmprovidername 0 5" | Out-File $provfile -Encoding ascii -Append
|
||||
|
||||
if (!(Test-Path $PSHOME\Traces))
|
||||
{
|
||||
@@ -192,7 +192,7 @@ function Enable-PSWSManCombinedTrace
|
||||
|
||||
Start-Trace -SessionName $script:pssession -OutputFilePath $logfile -ProviderFilePath $provfile -ETS
|
||||
|
||||
Remove-Item $provfile -Force -ea 0
|
||||
Remove-Item $provfile -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
function Disable-PSWSManCombinedTrace
|
||||
|
@@ -6,7 +6,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Eventing;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace System.Management.Automation.Tracing
|
||||
|
@@ -10,7 +10,7 @@ namespace System.Management.Automation.Tracing
|
||||
/// <summary>
|
||||
/// Tracer.
|
||||
/// </summary>
|
||||
public sealed partial class Tracer : System.Management.Automation.Tracing.EtwActivity
|
||||
public sealed partial class Tracer : EtwActivity
|
||||
{
|
||||
/// <summary>
|
||||
/// DebugMessage.
|
||||
|
@@ -10,7 +10,7 @@ namespace System.Management.Automation.Tracing
|
||||
/// <summary>
|
||||
/// Tracer.
|
||||
/// </summary>
|
||||
public sealed partial class Tracer : System.Management.Automation.Tracing.EtwActivity
|
||||
public sealed partial class Tracer : EtwActivity
|
||||
{
|
||||
/// <summary>
|
||||
/// Critical level.
|
||||
@@ -37,7 +37,6 @@ namespace System.Management.Automation.Tracing
|
||||
/// </summary>
|
||||
public const long KeywordAll = 0xFFFFFFFF;
|
||||
|
||||
private static readonly Guid providerId = Guid.Parse("a0c1853b-5c40-4b15-8766-3cf1c58f985a");
|
||||
private static readonly EventDescriptor WriteTransferEventEvent;
|
||||
private static readonly EventDescriptor DebugMessageEvent;
|
||||
private static readonly EventDescriptor M3PAbortingWorkflowExecutionEvent;
|
||||
@@ -218,17 +217,6 @@ namespace System.Management.Automation.Tracing
|
||||
/// </summary>
|
||||
public Tracer() : base() { }
|
||||
|
||||
/// <summary>
|
||||
/// Provider Guid.
|
||||
/// </summary>
|
||||
protected override Guid ProviderId
|
||||
{
|
||||
get
|
||||
{
|
||||
return providerId;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transfer Event.
|
||||
/// </summary>
|
||||
|
@@ -9,7 +9,7 @@ Describe "PSDiagnostics cmdlets tests." -Tag "CI", "RequireAdminOnWindows" {
|
||||
$PSDefaultParameterValues["it:skip"] = $true
|
||||
}
|
||||
else{
|
||||
$LogSettingBak = Get-LogProperties -Name Microsoft-Windows-PowerShell/$LogType
|
||||
$LogSettingBak = Get-LogProperties -Name PowerShellCore/$LogType
|
||||
}
|
||||
}
|
||||
AfterAll {
|
||||
@@ -20,37 +20,37 @@ Describe "PSDiagnostics cmdlets tests." -Tag "CI", "RequireAdminOnWindows" {
|
||||
}
|
||||
|
||||
Context "Test for Enable-PSTrace and Disable-PSTrace cmdlets." {
|
||||
It "Should enable $LogType logs for Microsoft-Windows-PowerShell." {
|
||||
[XML]$CurrentSetting = & wevtutil gl Microsoft-Windows-PowerShell/$LogType /f:xml
|
||||
It "Should enable $LogType logs for PowerShellCore." {
|
||||
[XML]$CurrentSetting = & wevtutil gl PowerShellCore/$LogType /f:xml
|
||||
if($CurrentSetting.Channel.Enabled -eq 'true'){
|
||||
& wevtutil sl Microsoft-Windows-PowerShell/$LogType /e:false /q
|
||||
& wevtutil sl PowerShellCore/$LogType /e:false /q
|
||||
}
|
||||
|
||||
Enable-PSTrace -Force
|
||||
|
||||
[XML]$ExpectedOutput = & wevtutil gl Microsoft-Windows-PowerShell/$LogType /f:xml
|
||||
[XML]$ExpectedOutput = & wevtutil gl PowerShellCore/$LogType /f:xml
|
||||
|
||||
$ExpectedOutput.Channel.enabled | Should -BeExactly 'true'
|
||||
}
|
||||
|
||||
It "Should disable $LogType logs for Microsoft-Windows-PowerShell." {
|
||||
[XML]$CurrentState = & wevtutil gl Microsoft-Windows-PowerShell/$LogType /f:xml
|
||||
It "Should disable $LogType logs for PowerShellCore." {
|
||||
[XML]$CurrentState = & wevtutil gl PowerShellCore/$LogType /f:xml
|
||||
if($CurrentState.channel.enabled -eq 'false'){
|
||||
& wevtutil sl Microsoft-Windows-PowerShell/$LogType /e:true /q
|
||||
& wevtutil sl PowerShellCore/$LogType /e:true /q
|
||||
}
|
||||
Disable-PSTrace
|
||||
|
||||
[XML]$ExpectedOutput = & wevtutil gl Microsoft-Windows-PowerShell/$LogType /f:xml
|
||||
[XML]$ExpectedOutput = & wevtutil gl PowerShellCore/$LogType /f:xml
|
||||
|
||||
$ExpectedOutput.Channel.enabled | Should -Be 'false'
|
||||
}
|
||||
}
|
||||
|
||||
Context "Test for Get-LogProperties cmdlet." {
|
||||
It "Should return properties of $LogType logs for 'Microsoft-Windows-PowerShell'." {
|
||||
[XML]$ExpectedOutput = wevtutil gl Microsoft-Windows-PowerShell/$LogType /f:xml
|
||||
It "Should return properties of $LogType logs for 'PowerShellCore'." {
|
||||
[XML]$ExpectedOutput = wevtutil gl PowerShellCore/$LogType /f:xml
|
||||
|
||||
$LogProperty = Get-LogProperties -Name Microsoft-Windows-PowerShell/$LogType
|
||||
$LogProperty = Get-LogProperties -Name PowerShellCore/$LogType
|
||||
|
||||
$LogProperty.Name | Should -Be $ExpectedOutput.channel.Name
|
||||
$LogProperty.Enabled | Should -Be $ExpectedOutput.channel.Enabled
|
||||
@@ -67,7 +67,7 @@ Describe "PSDiagnostics cmdlets tests." -Tag "CI", "RequireAdminOnWindows" {
|
||||
Context "Test for Set-LogProperties cmdlet." {
|
||||
BeforeAll {
|
||||
if ($IsWindows) {
|
||||
[XML]$WevtUtilBefore = wevtutil gl Microsoft-Windows-PowerShell/$LogType /f:xml
|
||||
[XML]$WevtUtilBefore = wevtutil gl PowerShellCore/$LogType /f:xml
|
||||
$LogPropertyToSet = [Microsoft.PowerShell.Diagnostics.LogDetails]::new($WevtUtilBefore.channel.Name,
|
||||
[bool]::Parse($WevtUtilBefore.channel.Enabled),
|
||||
$LogType,
|
||||
@@ -78,12 +78,12 @@ Describe "PSDiagnostics cmdlets tests." -Tag "CI", "RequireAdminOnWindows" {
|
||||
}
|
||||
}
|
||||
|
||||
It "Should invert AutoBackup setting of $LogType logs for 'Microsoft-Windows-PowerShell'." {
|
||||
It "Should invert AutoBackup setting of $LogType logs for 'PowerShellCore'." {
|
||||
$LogPropertyToSet.AutoBackup = -not $LogPropertyToSet.AutoBackup
|
||||
Set-LogProperties -LogDetails $LogPropertyToSet -Force
|
||||
|
||||
[XML]$ExpectedOutput = & wevtutil gl Microsoft-Windows-PowerShell/$LogType /f:xml
|
||||
(Get-LogProperties -Name Microsoft-Windows-PowerShell/$LogType).AutoBackup | Should -Be ([bool]::Parse($ExpectedOutput.Channel.Logging.AutoBackup))
|
||||
[XML]$ExpectedOutput = & wevtutil gl PowerShellCore/$LogType /f:xml
|
||||
(Get-LogProperties -Name PowerShellCore/$LogType).AutoBackup | Should -Be ([bool]::Parse($ExpectedOutput.Channel.Logging.AutoBackup))
|
||||
}
|
||||
|
||||
It "Should throw exception for invalid LogName." {
|
||||
|
Reference in New Issue
Block a user