Enable PowerShell Logging
10-25-2020
Language or Platform: Powershell
Code:
# Remotely Enabling Script Block PowerShell Logging
# Get DC list with:
# netdom query dc
$list = $PSScriptRoot + "\DClist.txt"
$Computers = Get-Content $list
foreach ($computer in $Computers) {
Invoke-Command –ComputerName $computer –ScriptBlock {
$basePath = 'HKLM:\\Software\\Policies\\Microsoft\\Windows' +
'\\PowerShell\\ScriptBlockLogging'
if(-not (Test-Path $basePath))
{
$null = New-Item $basePath -Force
# Create the correct properties
New-ItemProperty $basePath -Name "EnableScriptBlockLogging" -PropertyType Dword
}
Set-ItemProperty $basePath -Name EnableScriptBlockLogging -Value "1"
}
}
Back