-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEnable-PowerShellLogging.ps1
More file actions
45 lines (37 loc) · 2.22 KB
/
Copy pathEnable-PowerShellLogging.ps1
File metadata and controls
45 lines (37 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#Requires -RunAsAdministrator
#Requires -Version 5
<#
.DESCRIPTION
Alternative to using GPO for enabling/configuring PS logging
.SYNOPSIS
You heard me
.PARAMETER TranscriptPath
[string] (optional) path for saving transcript logs
.EXAMPLE
Enable-PowerShellLogging.ps1
.NOTES
Configure ACLs on transcript folder to restrict write-only privs to users...
and read/write/full for restricted admins only
#>
[CmdletBinding(SupportsShouldProcess)]
param (
[parameter(Mandatory=$False)]
[string] $TranscriptPath = ""
)
Write-Output "configuring registry for powershell logging"
if (!(Test-Path HKLM:\SOFTWARE\WOW6432Node\Policies\Microsoft\Windows\PowerShell\ModuleLogging)) {
New-Item -Path HKLM:\SOFTWARE\WOW6432Node\Policies\Microsoft\Windows\PowerShell\ModuleLogging
}
New-ItemProperty -Path HKLM:\SOFTWARE\WOW6432Node\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -PropertyType dword -Value 1 -Force
New-ItemProperty -Path HKLM:\SOFTWARE\WOW6432Node\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name ModuleNames -PropertyType string -Value "`* `= `*" -Force
if (!(Test-Path HKLM:\SOFTWARE\WOW6432Node\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging)) {
New-Item -Path HKLM:\SOFTWARE\WOW6432Node\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging
}
New-ItemProperty -Path HKLM:\SOFTWARE\WOW6432Node\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging -Name EnableScriptBlockLogging -PropertyType dword -Value 1 -Force
if (!(Test-Path HKLM:\SOFTWARE\WOW6432Node\Policies\Microsoft\Windows\PowerShell\Transcription)) {
New-Item -Path HKLM:\SOFTWARE\WOW6432Node\Policies\Microsoft\Windows\PowerShell\Transcription
}
New-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\Transcription -Name EnableTranscripting -PropertyType dword -Value 1 -Force
New-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\Transcription -Name EnableInvocationHeader -PropertyType dword -Value 1 -Force
New-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\Transcription -Name OutputDirectory -PropertyType string -Value $TranscriptPath -Force
Write-Output "registry configuration complete."