1
1
---
2
2
description : PowerShell logs internal operations from the engine, providers, and cmdlets to the Windows event log.
3
3
Locale : en-US
4
- ms.date : 10/ 07/2022
4
+ ms.date : 07/25/2023
5
5
online version : https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_logging_windows?view=powershell-7.2&WT.mc_id=ps-gethelp
6
6
schema : 2.0.0
7
7
title : about Logging Windows
@@ -18,13 +18,6 @@ the Windows event log.
18
18
PowerShell logs details about PowerShell operations, such as starting and
19
19
stopping the engine and providers, and executing PowerShell commands.
20
20
21
- > [ !NOTE]
22
- > Windows PowerShell versions 3.0, 4.0, 5.0, and 5.1 include ** EventLog**
23
- > cmdlets for the Windows event logs. In those versions, to display the list of
24
- > ** EventLog** cmdlets type: ` Get-Command -Noun EventLog ` . For more
25
- > information, see the cmdlet documentation and about_EventLogs for your
26
- > version of Windows PowerShell.
27
-
28
21
## Registering the PowerShell event provider on Windows
29
22
30
23
Unlike Linux or macOS, Windows requires the event provider to be registered
@@ -38,12 +31,12 @@ $PSHOME\RegisterManifest.ps1
38
31
## Viewing the PowerShell event log entries on Windows
39
32
40
33
PowerShell logs can be viewed using the Windows Event Viewer. The event log is
41
- located in the Application and Services Logs group and is named
42
- ` PowerShellCore ` . The associated ETW provider ` GUID ` is
34
+ located in the ** Application and Services Logs** group and is named
35
+ ** PowerShellCore** . The associated ETW provider GUID is
43
36
` {f90714a8-5509-434a-bf6d-b1624c8a19a2} ` .
44
37
45
38
When Script Block Logging is enabled, PowerShell logs the following events to
46
- the ` PowerShellCore/Operational ` log:
39
+ the ** PowerShellCore/Operational** log:
47
40
48
41
| Field | Value |
49
42
| ------- | ----------------- |
@@ -84,22 +77,22 @@ Script Block Logging can be enabled via Group Policy or a registry setting.
84
77
85
78
### Using Group Policy
86
79
87
- To enable automatic transcription, enable the ` Turn on PowerShell Script Block
88
- Logging` feature in Group Policy through ` Administrative Templates -> Windows
89
- Components -> Windows PowerShell` .
80
+ To enable automatic transcription, enable the ** Turn on PowerShell Script Block
81
+ Logging** feature in Group Policy through ** Administrative Templates** ->
82
+ ** PowerShell Core ** .
90
83
91
84
### Using the Registry
92
85
93
86
Run the following function:
94
87
95
88
``` powershell
96
- function Enable-PSScriptBlockLogging
97
- {
98
- $basePath = 'HKLM:\Software\Policies\Microsoft\Windows' +
99
- '\PowerShell\ScriptBlockLogging'
89
+ function Enable-PSScriptBlockLogging {
90
+ $basePath = @(
91
+ 'HKLM:\Software\Policies\Microsoft'
92
+ 'PowerShellCore\ScriptBlockLogging'
93
+ ) -join '\'
100
94
101
- if(-not (Test-Path $basePath))
102
- {
95
+ if (-not (Test-Path $basePath)) {
103
96
$null = New-Item $basePath -Force
104
97
}
105
98
@@ -127,13 +120,13 @@ content and decrypt content are kept separate.
127
120
The public key can be shared widely and isn't sensitive data. Any content
128
121
encrypted with this public key can only be decrypted by the private key. For
129
122
more information about Public Key Cryptography, see
130
- [ Wikipedia - Public Key Cryptography] [ 01 ] .
123
+ [ Wikipedia - Public Key Cryptography] [ 04 ] .
131
124
132
125
To enable a Protected Event Logging policy, deploy a public key to all machines
133
126
that have event log data to protect. The corresponding private key is used to
134
127
post-process the event logs at a more secure location such as a central event
135
- log collector, or [ SIEM] [ 02 ] aggregator. You can set up SIEM in Azure. For more
136
- information, see [ Generic SIEM integration] [ 03 ] .
128
+ log collector, or [ SIEM] [ 05 ] aggregator. You can set up SIEM in Azure. For more
129
+ information, see [ Generic SIEM integration] [ 01 ] .
137
130
138
131
### Enabling Protected Event Logging via Group Policy
139
132
@@ -153,33 +146,33 @@ can provide in one of several forms:
153
146
certificate store (can be deployed by PKI infrastructure).
154
147
155
148
The resulting certificate must have ` Document Encryption ` as an enhanced key
156
- usage (` 1.3.6.1.4.1.311.80.1 ` ), and either ` Data Encipherment ` or `Key
157
- Encipherment` key usages enabled.
149
+ usage (` 1.3.6.1.4.1.311.80.1 ` ), and either ` Data Encipherment ` or
150
+ ` Key Encipherment` key usages enabled.
158
151
159
152
> [ !WARNING]
160
153
> The private key shouldn't be deployed to the machines logging events. It
161
154
> should be kept in a secure location where you decrypt the messages.
162
155
163
156
### Decrypting Protected Event Logging messages
164
157
165
- The following script will retrieve and decrypt , assuming that you have the
158
+ The following script retrieves and decrypts events , assuming that you have the
166
159
private key:
167
160
168
161
``` powershell
169
162
Get-WinEvent Microsoft-Windows-PowerShell/Operational |
170
- Where-Object Id -eq 4104 | Unprotect-CmsMessage
163
+ Where-Object Id -eq 4104 |
164
+ Unprotect-CmsMessage
171
165
```
172
166
173
167
## See also
174
168
175
- - [ about_Logging_Non-Windows] [ 04 ]
176
- - [ PowerShell the Blue Team] [ 05 ]
177
- - [ Generic SIEM integration] [ 03 ]
178
-
179
- <!-- added link references -->
180
- [ 01 ] : https://en.wikipedia.org/wiki/Public-key_cryptography
181
- [ 02 ] : https://wikipedia.org/wiki/Security_information_and_event_management
182
- [ 03 ] : /cloud-app-security/siem
183
- [ 04 ] : about_Logging_Non-Windows.md
184
- [ 05 ] : https://devblogs.microsoft.com/powershell/powershell-the-blue-team/
185
- [ 06 ] : /cloud-app-security/siem
169
+ - [ about_Logging_Non-Windows] [ 02 ]
170
+ - [ PowerShell the Blue Team] [ 03 ]
171
+ - [ Generic SIEM integration] [ 01 ]
172
+
173
+ <!-- link references -->
174
+ [ 01 ] : /cloud-app-security/siem
175
+ [ 02 ] : about_Logging_Non-Windows.md
176
+ [ 03 ] : https://devblogs.microsoft.com/powershell/powershell-the-blue-team/
177
+ [ 04 ] : https://en.wikipedia.org/wiki/Public-key_cryptography
178
+ [ 05 ] : https://wikipedia.org/wiki/Security_information_and_event_management
0 commit comments