[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
本帖最后由 flashercs 于 2022-8-24 19:05 编辑
  1. $evt = Get-WinEvent -LogName Security -FilterXPath "Event[System[EventID=4625 and TimeCreated[timediff(@SystemTime)<=600000]]]" -MaxEvents 1 -ErrorAction SilentlyContinue
  2. $csvfile = "d:\$(Get-Date -Format 'yyyyMMdd').txt"
  3. $maxcount = 5
  4. if ($null -ne $evt) {
  5.   $ip = $evt.Properties[19].Value
  6.   $username = $evt.Properties[5].Value
  7.   $alpso = New-Object System.Collections.ArrayList
  8.   if (Test-Path -LiteralPath $csvfile) {
  9.     $null = Import-Csv -Path $csvfile -Encoding UTF8 -OutVariable alpso
  10.   }
  11.   $pso = 0 | Select-Object -Property @{n = 'IP'; e = { $ip } }, @{n = 'UserName'; e = { $username } }, @{n = 'Time'; e = { Get-Date } }
  12.   $null = $alpso.Add($pso)
  13.   $alpso | Export-Csv -Path $csvfile -Encoding UTF8 -NoTypeInformation
  14.   if (@($alpso | Where-Object { $_.IP -eq $ip }).Count -ge $maxcount) {
  15.     $firewallRuleDisplayName = "远程桌面黑名单"
  16.     $newRemoteIP = $ip
  17.     Get-NetFirewallRule -DisplayName $firewallRuleDisplayName | ForEach-Object {
  18.       $addrfilter = $_ | Get-NetFirewallAddressFilter
  19.       $arrOldRemoteIP = $addrfilter.CimInstanceProperties['RemoteAddress'].Value
  20.       $arrNewRemoteIP = @(
  21.         if ($null -ne $arrOldRemoteIP) { $arrOldRemoteIP }
  22.         $newRemoteIP
  23.       ) | Sort-Object -Unique
  24.       $_ | Set-NetFirewallRule -RemoteAddress $arrNewRemoteIP
  25.     }
  26.   }
  27. }
复制代码
1

评分人数

微信:flashercs
QQ:49908356

TOP

回复 3# 522235677


    改了一下
微信:flashercs
QQ:49908356

TOP

返回列表