4 PowerShell Logging
4 PowerShell Logging
4 PowerShell Logging
In addition to the very limited default logging, you can choose to enable 3
additional log types as follows.
Default Logging
First, we will look at the Engine and Provider Lifecycle events that are
written to the “Application and Services Logs Windows PowerShell”
log. Open Event Viewer to this location to view these logs.
To open Event Viewer, do a search for “event viewer” in the search bar.
[ScriptBlock].GetField('signatures','NonPublic,Static').GetValue($null) | sort
We haven’t enabled any of the optional logging yet, but if we look at the
Microsoft\Windows\PowerShell\Operational log we will see that these
suspicious scripts are being logged there as well. I’ve included a tool on the
desktop called TailPSopLog on the desktop of the lab VM that shows
these events without having to refresh the view. Double click the
TailPSopLog application and then run the Suspicious script again and
watch for the suspicious events to show in the log.
Optional Logging
You now have an administrative PowerShell prompt where you can easily
set the logging options. If you want to see the details of what the script
does, review the Set-PSLogging.ps1 file in the Tools directory.
Note: Logging options are set at the time the PowerShell window opens so
you must start a new PowerShell session to see the effects from the
logging changes you make.
Now start a new PowerShell session and execute some commands and
sample scripts. The color coding in the TailPSopLog tool will help clarify
which events are module logs (blue) or script block logs (yellow). If you see
a dark yellow log, that is a script block log with a level of warning that gets
generated from suspicious commands.
Note: If you ever see the word select in the title bar of the TailPSopLog or
the PowerShell window it means that output is paused. You won’t see any
additional output in a window with select in the title bar until you click in the
window and press the space bar. This will cause the output to continue to
flow to the screen.
Transcription logging is a different type of log than script block and module
logging. Transcription logging doesn’t show up in a Windows event log and
instead is written out to files. The directory for these files is configurable
and the LogMenu tool sets it to the C:\Users\IEUser\PSTranscripts
directory.
In the transcripts folder you will see a folder for each day and within each
folder you will find a text file for each PowerShell session that is created. A
transcript is an “over the shoulder” version of logging where you see
In the example transcript above, you can see the effect of having double-
clicked the LogMenu shortcut (the Show-LoggingMenu.ps1 script was
executed). You can also see the menu that was output to the screen.
Look at the transcripts for your sessions to get familiar with the type of
information available to you from these logs.