Windows-OPS

Windows 常用运维命令—powershell

通过PID找对应目录
1
wmic process get name,executablepath,processid|findstr pid

查看当前连接数

1
netstat -an|findstr "ESTABLISHED"Measure-Object

使用powershel实现搜索文件

1
Get-Content C:\Windows\system32\drivers\etc\hosts | Out-String -Stream | Select-String "localhost"

查询过期文件

1
2
$path = "C:\inetpub\logs\LogFiles\W3SVC1\"
Get-ChildItem -Path $path -Recurse -ErrorAction:SilentlyContinue | ` Where-Object -FilterScript {(((get-date) - ($_.CreationTime)).days -gt 10 ` -and $_.PsISContainer -ne $True)} | Select-Object FullName
  • Select-Object FullName:查找
  • Remove-Item:删除
  • Remove-Item -Force:删除,包括只读和隐藏

重启指定服务

1
2
3
4
5
6
7
8
$cpuper = Get-Counter '\Processor(_Total)\% Processor Time' | ForEach-Object {$_.CounterSamples} | ForEach-Object {$_.CookedValue}

$cpuper = "{0:f}" -f $cpuper

if($cpuper -gt 60)
{
Restart-Service -Name <service name> -Force
}

实现DNAT

1
netsh interface portproxy add v4tov4 listenaddress=172.20.53.1 listenport=14941 connectaddress=172.20.53.2 connectport=3389

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!