
PowerShell 是 Windows 平台上最被低估的运维利器。本文整理了我们团队日常使用频率最高的脚本模板,拿来即用。

一、批量文件处理
1.1 按扩展名批量重命名
Get-ChildItem -Path .\docs -Filter *.txt |
Rename-Item -NewName { $_.BaseName + '.md' }二、系统信息采集
2.1 导出硬件清单
Get-CimInstance Win32_ComputerSystem | Select-Object Name, TotalPhysicalMemory |
Export-Csv -Path .\inventory.csv -NoTypeInformation三、注册表批量操作
- 读取键值:
Get-ItemProperty - 写入键值:
Set-ItemProperty - 递归删除:
Remove-Item -Recurse
总结
把重复劳动脚本化,是运维效率的第一杠杆。建议把本文模板收藏进个人代码库,逐步沉淀成自己的工具箱。