0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Powershellでfirewallのremoteipアドレスを設定する

Last updated at Posted at 2017-02-15
$rc=0
$inifile="c:\work/list.ini"
$rule="Windows Remote Management (HTTPS-In)"


Write-Output "

処理開始

---------------------
"

if (Test-Path $inifile) {
    Write-Host $inifile is found!
} else {
    Write-Host $inifile is not found!
    $rc=1
    exit $rc
}

if (-not(Get-NetFirewallRule | Where-Object DisplayName -eq $rule)) {
    Write-Host firewall rule is not found!
    $rc=1
    exit $rc
} else {
    Write-Host firewall rule is found!
}

$remoteip=Get-NetFirewallRule | Where-Object DisplayName -eq $rule | Get-NetFirewallAddressFilter  | Select-Object RemoteAddress
$currentip=$remoteip.RemoteAddress | Sort-Object
$newip=Get-Content $inifile | Sort-Object
$diff=Compare-Object $currentip $newip

if($null -eq $diff){
    Write-Output '
    
    no difference
    
    ' 
}
else{
    Write-Output $diff 
}

$title = "実行確認"
$message = "実行してよろしいですか?"
$objYes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes","YES"
$objNo = New-Object System.Management.Automation.Host.ChoiceDescription "&No","NO"
$objOptions = [System.Management.Automation.Host.ChoiceDescription[]]($objYes, $objNo)
$resultVal = $host.ui.PromptForChoice($title, $message, $objOptions, 1)
if ($resultVal -ne 0) { exit }

Get-NetFirewallRule -Enabled True | Where-Object {$_.DisplayName -eq $rule} | Set-NetFirewallRule -RemoteAddress $newip

Write-Output "


--------------result--------------


"
$currentip

write-host END
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?