Set-ErrorReportingStatus
Windows: Configures Windows Error Reporting (WER) status
#Requires -Version 5.1
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)]
[bool]$Enabled,
[string]$ComputerName = $env:COMPUTERNAME,
[pscredential]$Credential
)
Process {
try {
$scriptBlock = {
Param($IsEnabled)
Import-Module WindowsErrorReporting -ErrorAction SilentlyContinue
if ($IsEnabled) {
Enable-WindowsErrorReporting -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting" -Name "Disabled" -Value 0 -Force -ErrorAction SilentlyContinue
}
else {
Disable-WindowsErrorReporting -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting" -Name "Disabled" -Value 1 -Force -ErrorAction SilentlyContinue
}
Get-WindowsErrorReporting -ErrorAction SilentlyContinue
}
if ($ComputerName -ne $env:COMPUTERNAME) {
$invokeParams = @{
'ComputerName' = $ComputerName
'ScriptBlock' = $scriptBlock
'ArgumentList' = $Enabled
'ErrorAction' = 'Stop'
}
if ($null -ne $Credential) {
$invokeParams.Add('Credential', $Credential)
}
$status = Invoke-Command @invokeParams
}
else {
$status = &$scriptBlock -IsEnabled $Enabled
}
$result = [PSCustomObject]@{
WEREnabled = $Enabled
ComputerName = $ComputerName
Action = "WERConfigured"
Status = "Success"
Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
}
Write-Output $result
}
catch {
throw
}
}Specifies whether to enable or disable Windows Error Reporting.
Specifies the name of the target computer. Defaults to the local computer.
Specifies a PSCredential object for remote connection.