软件测试职业探索

powershell札记2_脚本学习

2019-06-14  本文已影响1人  皮皮大

添加windows防火墙入站规则

PowerShell命令New-NetFirewallRule可以很方便的快速添加入站规则到本地的防火墙里,学习网址如下:

BLCHEN的空间

Write-Host -ForegroundColor Cyan "Creating new inbound rule Http"
New-NetFirewallRule -DisplayName "Http" -Direction Inbound -LocalPort 80 -RemotePort Any -Protocol TCP -Enabled True
Write-Host -ForegroundColor Cyan "Creating new outbound rule Http"
New-NetFirewallRule -DisplayName "Http" -Direction Outbound -LocalPort 80 -RemotePort Any -Protocol TCP -Enabled True
Write-Host -ForegroundColor Cyan "Creating new rule Allow Ping"
New-NetFirewallRule -DisplayName "Allow Ping" -Description "Allow ping" -Protocol ICMPv4 -IcmpType 8 -Enabled True -Profile Any -Action Allow 
# create new excel instance
$objExcel = New-Object -comobject Excel.Application    # 创建一个Excel对象
$objExcel.Visible = $True
$objWorkbook = $objExcel.Workbooks.Add()
$objWorksheet = $objWorkbook.Worksheets.Item(1)

# write information to the excel file
$i = 0
$first10 = (ps | sort ws -Descending | select -first 10)   # 显示占用内存最大的10个进程。
$first10 | foreach -Process {$i++; $objWorksheet.Cells.Item($i,1) = $_.name; $objWorksheet.Cells.Item($i,2) = $_.ws}
$otherMem = (ps | measure ws -s).Sum - ($first10 | measure ws -s).Sum
$objWorksheet.Cells.Item(11,1) = "Others"; $objWorksheet.Cells.Item(11,2) = $otherMem

# draw the pie chart
$objCharts = $objWorksheet.ChartObjects()
$objChart = $objCharts.Add(0, 0, 500, 300)
$objChart.Chart.SetSourceData($objWorksheet.range("A1:B11"), 2)
$objChart.Chart.ChartType = 70
$objChart.Chart.ApplyDataLabels(5)

# 运行结果如下 
image.png
上一篇下一篇

猜你喜欢

热点阅读