-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFirewallDrive.psm1
90 lines (76 loc) · 2.24 KB
/
FirewallDrive.psm1
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using namespace Microsoft.PowerShell.SHiPS
[SHiPSProvider(UseCache = $false)]
class FirewallRoot : SHiPSDirectory
{
# Default constructor
FirewallRoot([string]$name):base($name)
{
}
[object[]] GetChildItem()
{
$Directions = @('Inbound','Outbound')
$Output = $Directions | ForEach-Object -Process {
[Direction]::new($_)
}
return $Output
}
}
[SHiPSProvider(UseCache = $True)]
class Direction : SHiPSDirectory
{
[string]$Direction
Direction([string]$Name):base($Name)
{
$this.Direction = $Name
}
[object[]] GetChildItem ()
{
# Listing all Profiles regardless of current direction.
$Profiles = Get-NetFirewallProfile | ForEach-Object -Process {
[Profile]::new($_.Name,$_)
}
return $Profiles
}
}
[SHiPSProvider(UseCache = $true)]
class Profile : SHiPSDirectory
{
[object] $ProfileType
[String] $Enabled
[String] $LogAllowed
[String] $LogMaxSizeKilobytes
Profile([string]$name,$CurrentProfile):base($name)
{
$this.ProfileType = $CurrentProfile
$this.LogAllowed = $CurrentProfile.LogAllowed
$this.LogMaxSizeKilobytes = $CurrentProfile.LogMaxSizeKilobytes
$this.Enabled = $CurrentProfile.Enabled
}
[object[]] GetChildItem ()
{
$FirewallRules = Get-NetFirewallRule -AssociatedNetFirewallProfile $this.ProfileType | ForEach-Object -Process {
[FirewallRule]::New($_.Name,$_)
}
return $FirewallRules
}
}
[SHiPSProvider(UseCache = $true)]
class FirewallRule : SHiPSLeaf
{
[String] $RuleDescription
[String] $RuleProfile
[String] $Name
[String] $RuleState
[String] $RuleStatus
FirewallRule([string]$Name, [object]$Rule):base($name)
{
$this.Name = $Name
$this.RuleDescription = $Rule.Description
$this.RuleProfile = $Rule.Profile
$this.RuleStatus = $Rule.Status
$this.RuleState = 'Enabled'
if( $Rule.Enabled -eq 'False' ){
$this.RuleState = 'Disabled'
}
}
}