$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
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme