mirror of
https://github.com/Thumbscrew/PSWinFW.git
synced 2025-01-18 17:45:47 +00:00
commit
a57e5ef79a
@ -23,20 +23,24 @@ function Get-PSFirewallLog {
|
|||||||
[string]
|
[string]
|
||||||
$LogProfile,
|
$LogProfile,
|
||||||
|
|
||||||
# Number of firewall events to retrieve. Defaults to 0 (All events).
|
# Number of firewall events to retrieve. Defaults to -1 (All events).
|
||||||
[Parameter(Mandatory = $false)]
|
[Parameter(Mandatory = $false)]
|
||||||
[int]
|
[int]
|
||||||
$Tail = 0,
|
$Tail = -1,
|
||||||
|
|
||||||
# ComputerName to retrieve log from
|
# ComputerName to retrieve log from
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = 'remote')]
|
[Parameter(Mandatory = $true, ParameterSetName = 'remote')]
|
||||||
[string]
|
[string]
|
||||||
$ComputerName
|
$ComputerName,
|
||||||
|
|
||||||
|
# Follow the log
|
||||||
|
[Parameter(Mandatory = $false)]
|
||||||
|
[switch]
|
||||||
|
$Wait
|
||||||
)
|
)
|
||||||
|
|
||||||
begin {
|
begin {
|
||||||
if($PSCmdlet.ParameterSetName -eq 'auto') {
|
if($PSCmdlet.ParameterSetName -eq 'auto') {
|
||||||
# $Path = [Environment]::ExpandEnvironmentVariables((Get-ItemProperty -Path ("HKLM:\SOFTWARE\Policies\Microsoft\WindowsFirewall\{0}Profile\Logging" -f $LogProfile) -Name "LogFilePath").LogFilePath)
|
|
||||||
$Path = Get-PSFirewallLogPath -LogProfile $LogProfile -Verbose:$VerbosePreference
|
$Path = Get-PSFirewallLogPath -LogProfile $LogProfile -Verbose:$VerbosePreference
|
||||||
}
|
}
|
||||||
elseif($PSCmdlet.ParameterSetName -eq 'remote') {
|
elseif($PSCmdlet.ParameterSetName -eq 'remote') {
|
||||||
@ -59,17 +63,6 @@ function Get-PSFirewallLog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(Test-Path $logPath) {
|
if(Test-Path $logPath) {
|
||||||
$log = Get-Content $logPath
|
|
||||||
|
|
||||||
if($log.Length -gt 0) {
|
|
||||||
# Remove header lines
|
|
||||||
$log = $log[5..($log.Length - 1)]
|
|
||||||
|
|
||||||
if($Tail -gt 0) {
|
|
||||||
$startIndex = if($Tail -lt $log.Length) { $log.Length - $Tail } else { 0 }
|
|
||||||
|
|
||||||
$log = $log[$startIndex..($log.Length - 1)]
|
|
||||||
}
|
|
||||||
|
|
||||||
$members = @{
|
$members = @{
|
||||||
"Date" = 0
|
"Date" = 0
|
||||||
@ -91,8 +84,24 @@ function Get-PSFirewallLog {
|
|||||||
"Path" = 16
|
"Path" = 16
|
||||||
}
|
}
|
||||||
|
|
||||||
$log | ForEach-Object {
|
$count = (Get-Content -Path $logPath).Count
|
||||||
|
|
||||||
|
# Check if outputting all events from the log and cut the first 5 lines that aren't events.
|
||||||
|
if(($Tail -lt 0) -or ($Tail -gt $count)) {
|
||||||
|
$Tail = $count - 5
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Verbose "Log has $count lines. Retrieving $Tail lines."
|
||||||
|
|
||||||
|
$c = "Get-Content -Path $logPath -Tail $Tail"
|
||||||
|
|
||||||
|
if($Wait) {
|
||||||
|
$c = "$c -Wait"
|
||||||
|
}
|
||||||
|
|
||||||
|
Invoke-Expression $c | ForEach-Object {
|
||||||
$line = $_
|
$line = $_
|
||||||
|
|
||||||
$split = $line -split ('\s')
|
$split = $line -split ('\s')
|
||||||
|
|
||||||
$fwEvent = New-Object PSCustomObject
|
$fwEvent = New-Object PSCustomObject
|
||||||
@ -106,10 +115,6 @@ function Get-PSFirewallLog {
|
|||||||
$fwEvent
|
$fwEvent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
Write-Error "File $logPath has zero length."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
Write-Error "Failed to retrieve log at $logPath."
|
Write-Error "Failed to retrieve log at $logPath."
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ function Get-PSFirewallLogPath {
|
|||||||
if($statusChanged) {
|
if($statusChanged) {
|
||||||
Write-Verbose ("Reverting status of $serviceName Service to {0}." -f $remoteRegistry.Status)
|
Write-Verbose ("Reverting status of $serviceName Service to {0}." -f $remoteRegistry.Status)
|
||||||
# Set-Service -Name $serviceName -ComputerName $ComputerName -Status $remoteRegistry.Status
|
# Set-Service -Name $serviceName -ComputerName $ComputerName -Status $remoteRegistry.Status
|
||||||
# Need to use Invoke-Command as Set-Service won't stop a service that has dependancies
|
# Need to use Invoke-Command as Set-Service won't stop a service that has dependencies
|
||||||
Invoke-Command -ComputerName $ComputerName -ScriptBlock { Stop-Service -Name "RemoteRegistry" }
|
Invoke-Command -ComputerName $ComputerName -ScriptBlock { Stop-Service -Name "RemoteRegistry" }
|
||||||
|
|
||||||
# Verify that service has been restored to its original state.
|
# Verify that service has been restored to its original state.
|
||||||
|
Loading…
Reference in New Issue
Block a user