Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- -----------------------------------------------------------------------------------------------------------
- Titre: "FixUp NetFirewallRule Windows 8.1 @ 10.ps1"
- Author: Powershell_PC_Aide
- PowerShell ver: minimum v5
- Date: 22-08-2019
- Update:
- Dependents: WinRM (Enable-PSRemoting)
- Elevated: Y
- O/P: https://imgur.com/k54hwJE
- ----------------------------------------------------------------------------------------------------------
- #>
- #Switch - Disabled Firewall Rule
- [cmdletbinding()]
- Param([Switch] $Disable)
- #Errors
- $ErrorActionPreference = "SilentlyContinue"
- #File txt (format: FQDN / line)
- $PCs = Get-Content ".\List PCs.txt"
- #Header
- "FQDN," + "DisplayName," + "Name"
- #List PCs
- foreach ($PC in $PCs)
- {#debut
- #Online
- $Ping = Test-Connection $PC -Quiet -Count 1
- #True
- if ($Ping)
- {
- #Test-wsMan (WinRM service is running)
- $WSManRunning = Test-WSMan $PC
- #True
- if ($WSManRunning)
- {
- #True (set)
- if($Disable)
- {
- Invoke-Command -ComputerName $PC -ScriptBlock `
- {
- $DisplayName = (Get-NetFirewallRule | Where-Object {$_.Enabled -eq $true -and $_.Action -eq "Block"}).DisplayName
- Set-NetFirewallRule -DisplayName $DisplayName -Enabled False
- }
- }
- #False (Get)
- else
- {
- Invoke-Command -ComputerName $PC -ScriptBlock `
- {
- #Firewall
- $Firewall = Get-NetFirewallRule
- #Condition
- $Condition = $Firewall | Where-Object {$_.Enabled -eq $true -and $_.Action -eq "Block"}
- #Rule
- $Condition |
- ForEach-Object{
- $Rule = $_
- $_ | Get-NetFirewallPortFilter |
- ForEach-Object{
- #StdOut console
- "$env:computerName.$env:USERDNSDOMAIN" `
- + "," + $Rule.DisplayName `
- + "," + $Rule.Name
- }
- }
- }
- }
- }
- #False (WinRM not running)
- else
- {
- $PC + ": " + "WinRM is not running"
- }
- }
- #False (Offline)
- else
- {
- (Write-Host $PC -ForegroundColor Red ": " -NoNewline) + "Offline"
- "`n"
- }
- }#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement