mirror of
https://github.com/Thumbscrew/PSWinFW.git
synced 2025-01-18 17:45:47 +00:00
Merge pull request #15 from Thumbscrew/dont-use-remote-reg
InferPath switch
This commit is contained in:
commit
8f1755a09a
@ -36,7 +36,12 @@ function Get-PSFirewallLog {
|
||||
# Follow the log
|
||||
[Parameter(Mandatory = $false)]
|
||||
[switch]
|
||||
$Wait
|
||||
$Wait,
|
||||
|
||||
# Use local machine's registry setting to infer remote machine's log path
|
||||
[Parameter(Mandatory = $false, ParameterSetName = 'remote')]
|
||||
[switch]
|
||||
$InferPath
|
||||
)
|
||||
|
||||
begin {
|
||||
@ -44,7 +49,13 @@ function Get-PSFirewallLog {
|
||||
$Path = Get-PSFirewallLogPath -LogProfile $LogProfile -Verbose:$VerbosePreference
|
||||
}
|
||||
elseif($PSCmdlet.ParameterSetName -eq 'remote') {
|
||||
$Path = Get-PSFirewallLogPath -LogProfile $LogProfile -ComputerName $ComputerName -Verbose:$VerbosePreference
|
||||
$lpc = "Get-PSFirewallLogPath -LogProfile $LogProfile -ComputerName $ComputerName"
|
||||
|
||||
if($InferPath) {
|
||||
$lpc += " -InferPath"
|
||||
}
|
||||
|
||||
$Path = Invoke-Expression $lpc -Verbose:$VerbosePreference
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,13 +9,29 @@ function Get-PSFirewallLogPath {
|
||||
# Remote Host to retrieve from
|
||||
[Parameter(Mandatory = $false, ParameterSetName = 'remote')]
|
||||
[string]
|
||||
$ComputerName
|
||||
$ComputerName,
|
||||
|
||||
# Use local machine's registry setting to infer remote machine's log path
|
||||
[Parameter(Mandatory = $false, ParameterSetName = 'remote')]
|
||||
[switch]
|
||||
$InferPath
|
||||
)
|
||||
|
||||
process {
|
||||
$serviceName = "RemoteRegistry"
|
||||
|
||||
if($PSCmdlet.ParameterSetName -eq 'remote') {
|
||||
|
||||
if($InferPath) {
|
||||
# Get local registry key entry
|
||||
$localPath = [Environment]::ExpandEnvironmentVariables((Get-ItemProperty -Path ("HKLM:\SOFTWARE\Policies\Microsoft\WindowsFirewall\{0}Profile\Logging" -f $LogProfile) -Name "LogFilePath").LogFilePath)
|
||||
|
||||
if($null -eq $localPath) {
|
||||
$defaultPath = "$ENV:SystemRoot\system32\LogFiles\Firewall\pfirewall.log"
|
||||
Write-Warning "Path for $LogProfile firewall log not defined in registry. Assuming default path of $defaultPath"
|
||||
$localPath = $defaultPath
|
||||
}
|
||||
}
|
||||
else {
|
||||
$serviceName = "RemoteRegistry"
|
||||
$startTypeChanged = $false
|
||||
$statusChanged = $false
|
||||
|
||||
@ -80,6 +96,7 @@ function Get-PSFirewallLogPath {
|
||||
Write-Warning "Failed to revert startup type of $serviceName to $($remoteRegistry.StartType)!"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Do the conversion to UNC path
|
||||
$path = "\\$ComputerName\" + $localPath.replace(':', '$')
|
||||
@ -91,7 +108,9 @@ function Get-PSFirewallLogPath {
|
||||
$path = [Environment]::ExpandEnvironmentVariables((Get-ItemProperty -Path ("HKLM:\SOFTWARE\Policies\Microsoft\WindowsFirewall\{0}Profile\Logging" -f $LogProfile) -Name "LogFilePath").LogFilePath)
|
||||
|
||||
if($null -eq $path) {
|
||||
$path = "$ENV:SystemRoot\system32\LogFiles\Firewall\pfirewall.log"
|
||||
$defaultPath = "$ENV:SystemRoot\system32\LogFiles\Firewall\pfirewall.log"
|
||||
Write-Warning "Path for $LogProfile firewall log not defined in registry. Assuming default path of $defaultPath"
|
||||
$path = $defaultPath
|
||||
}
|
||||
|
||||
return $path
|
||||
|
Loading…
Reference in New Issue
Block a user