首页 > 系统相关 >这些 PowerShell 命令适用于清理 Windows 中更多不同组件和服务的日志。通过定期执行这些清理操作,可以有效地管理磁盘空间和维护系统的性能。记得在执行之前做好必要的确认和备份工作,以免造

这些 PowerShell 命令适用于清理 Windows 中更多不同组件和服务的日志。通过定期执行这些清理操作,可以有效地管理磁盘空间和维护系统的性能。记得在执行之前做好必要的确认和备份工作,以免造

时间:2024-07-06 23:30:47浏览次数:1  
标签:powershellCopy Code WinEvent Get Windows 清理 Remove 磁盘空间

  1. 清理临时文件

    powershellCopy Code
    Remove-Item -Path "$env:TEMP\*" -Force -Recurse
    Remove-Item -Path "$env:LOCALAPPDATA\Temp\*" -Force -Recurse
  2. 清理回收站

    powershellCopy Code
    Clear-RecycleBin -Force
  3. 清理浏览器缓存(例如清理 Chrome 缓存):

    powershellCopy Code
    Remove-Item -Path "$env:LOCALAPPDATA\Google\Chrome\User Data\Default\Cache\*" -Force -Recurse
  4. 清理 Windows 更新临时文件

    powershellCopy Code
    Get-WindowsUpdateLog | Remove-WindowsUpdateLog
  5. 清理 Windows 错误报告和日志文件

    powershellCopy Code
    Get-WinEvent -LogName "Application", "System" | Where-Object { $_.TimeCreated -lt (Get-Date).AddDays(-30) } | Remove-WinEvent
  6. 优化系统启动项: 可以通过 PowerShell 管理注册表或启动文件夹来禁用或管理启动项,这需要一些谨慎操作。

  7. 清理远程桌面连接历史记录

    powershellCopy Code
    Clear-History -CommandLineType "RemoteDesktop"
  8. 清理 Powershell 历史记录

    powershellCopy Code
    Clear-History
  9. 清理系统日志文件

    powershellCopy Code
    Clear-EventLog -LogName "Application", "System"
  10. 清理 IIS 日志文件

    powershellCopy Code
    Get-ChildItem -Path "C:\inetpub\logs\LogFiles" | Remove-Item -Force -Recurse
  11. 清理临时 IIS 文件

    powershellCopy Code
    Remove-Item -Path "C:\Windows\Temp\*" -Force -Recurse
  12. 清理 Windows 更新缓存

    powershellCopy Code
    Clean-CMUpdatePackage
  13. 清理 Windows Defender 定义文件缓存

    powershellCopy Code
    Clear-MpThreatCatalog
  14. 清理 Windows 更新日志和临时文件

    powershellCopy Code
    Remove-Item -Path "$env:LOCALAPPDATA\Temp\WindowsUpdateLogs\*" -Force -Recurse
  15. 清理 PowerShell 缓存

    powershellCopy Code
    Clear-Host
  16. 清理用户临时文件和配置

    powershellCopy Code
    Remove-Item -Path "$env:LOCALAPPDATA\Temp\*" -Force -Recurse
    Remove-Item -Path "$env:APPDATA\Microsoft\Windows\Recent\*" -Force -Recurse
  17. 清理 Windows 搜索索引

    powershellCopy Code
    Get-WindowsSearchIndex | Reset-WindowsSearchIndex
  18. 清理 Windows 更新备份文件

    powershellCopy Code
    Dism.exe /Online /Cleanup-Image /StartComponentCleanup /ResetBase
  1. 清理旧的 Windows 安装文件

    powershellCopy Code
    Dism.exe /Online /Cleanup-Image /StartComponentCleanup /ResetBase
  2. 清理 Windows Event 日志文件

    powershellCopy Code
    Clear-EventLog -LogName "Application", "System"
  3. 清理 Windows Update 下载的临时文件

    powershellCopy Code
    Remove-Item -Path "$env:SYSTEMROOT\SoftwareDistribution\Download\*" -Force -Recurse
  4. 清理 Windows 更新错误报告

    powershellCopy Code
    Remove-Item -Path "$env:LOCALAPPDATA\Microsoft\Windows\Windows Error Reporting\*" -Force -Recurse
  5. 清理 PowerShell 临时文件

    powershellCopy Code
    Remove-Item -Path "$env:LOCALAPPDATA\Microsoft\Windows\PowerShell\*" -Force -Recurse
  6. 清理 Windows 应用程序日志

    powershellCopy Code
    Get-WinEvent -LogName "Application" | Remove-WinEvent
  7. 清理 Windows 防火墙日志

    powershellCopy Code
    Get-NetFirewallProfile | Get-NetFirewallLog | Clear-NetFirewallLog
  8. 清理 Windows 系统日志

    powershellCopy Code
    Get-WinEvent -LogName "System" | Remove-WinEvent
  9. 清理 Windows 运行时组件日志

    powershellCopy Code
    Get-WinEvent -LogName "Runtime" | Remove-WinEvent
  10. 清理 Windows 应用程序故障诊断日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-Diagnostics-Performance/Operational" | Remove-WinEvent
  11. 清理 IIS 日志(特定日期范围内):

    powershellCopy Code
    Get-ChildItem -Path "C:\inetpub\logs\LogFiles" -Recurse | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-30)} | Remove-Item -Force
  12. 清理 Windows PowerShell 工作流和任务注册表日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-PowerShell/Operational" | Remove-WinEvent
  13. 清理 Windows 安全审计日志

    powershellCopy Code
    Get-WinEvent -LogName "Security" | Remove-WinEvent
  14. 清理 Windows 组件事件日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-WinINet/Analytic" | Remove-WinEvent
  15. 清除临时文件

    powershellCopy Code
    Remove-Item -Path "$env:TEMP\*" -Force -Recurse
  16. 清除 Windows 更新缓存

    powershellCopy Code
    Remove-Item -Path "$env:SystemRoot\SoftwareDistribution\Download\*" -Force -Recurse
  17. 清除事件日志(需以管理员身份运行):

    powershellCopy Code
    wevtutil el | ForEach-Object {wevtutil cl $_}
  18. 清除用户临时文件

    powershellCopy Code
    Remove-Item -Path "$env:USERPROFILE\AppData\Local\Temp\*" -Force -Recurse
  19. 清除 Internet Explorer 缓存

    powershellCopy Code
    Clear-IECache
  20. 清除 Windows Store 缓存

    powershellCopy Code
    Get-AppxPackage -AllUsers | Where-Object {$_.Name -like "*WindowsStore*"} | Remove-AppxPackage
  21. 清除 PowerShell 缓存

    powershellCopy Code
    Clear-History
  22. 清除内存

    powershellCopy Code
    Clear-Host
  23. 优化系统磁盘

    powershellCopy Code
    Optimize-Volume -DriveLetter C -Defrag -Verbose
  24. 清理 Windows PowerShell Core 日志

    powershellCopy Code
    Get-WinEvent -LogName "Windows PowerShell Core/Operational" | Remove-WinEvent
  25. 清理 Windows Defender 防病毒日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-Windows Defender/Operational" | Remove-WinEvent
  26. 清理 Hyper-V 虚拟机日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-Hyper-V-Worker-Admin" | Remove-WinEvent
  27. 清理 Windows 搜索索引日志

    powershellCopy Code
    Get-WinEvent -LogName "Windows Search/Operational" | Remove-WinEvent
  28. 清理 DNS 服务器日志

    powershellCopy Code
    Get-WinEvent -LogName "DNS Server/Analytical" | Remove-WinEvent
  29. 清理 DHCP 服务器日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-DHCP Server Events/Admin" | Remove-WinEvent
  30. 清理 Windows 版本管理日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-WindowsUpdateClient/Operational" | Remove-WinEvent
  31. 清理 Windows 内核事件日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-Kernel-EventTracing/Operational" | Remove-WinEvent
  32. 清理 Windows 远程桌面服务日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-TerminalServices-LocalSessionManager/Operational" | Remove-WinEvent
  33. 清理 Windows 存储空间直通日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-StorageSpaces-Driver/Operational" | Remove-WinEvent
  34. 清理 Windows 进程活动日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-ProcessExit/Operational" | Remove-WinEvent
  35. 清理 Windows 进程启动日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-ProcessCreation/Operational" | Remove-WinEvent
  36. 清理 Windows 网络共享日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-Shell-Core/Operational" | Remove-WinEvent
  37. 清理 Windows 升级日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-WindowsUpdateClient/Operational" | Remove-WinEvent
  38. 清理 Windows 存储传输服务日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-StorDiag/Operational" | Remove-WinEvent
  39. 清理 Windows 连接性解析器日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-ConnectivityAnalyzer/Operational" | Remove-WinEvent
  40. 清理 Windows 设备管理器日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-DeviceManagement-Enterprise-Diagnostics-Provider/Admin" | Remove-WinEvent
  41. 清理 Windows 打印服务日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-PrintService/Operational" | Remove-WinEvent
  42. 清理 Windows 驱动程序框架服务日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-DriverFrameworks-UserMode/Operational" | Remove-WinEvent
  43. 清理 Windows 存储日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-Storage-ClassPnP/Operational" | Remove-WinEvent
  44. 清理 Windows 文件共享服务日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-SMBServer/Audit" | Remove-WinEvent
  45. 清理 Windows 安全审计日志

    powershellCopy Code
    Get-WinEvent -LogName "Security/AuditSuccess", "Security/AuditFailure" | Remove-WinEvent
  46. 清理 Windows 系统事件通知服务日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-Sens/Operational" | Remove-WinEvent
  47. 清理 Windows 远程注册表服务日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-RemoteRegistry/Operational" | Remove-WinEvent
  48. 清理 Windows 电源管理日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-Power-Troubleshooter/Operational" | Remove-WinEvent
  49. 清理 Windows DHCP 客户端日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-DHCP-Client/Operational" | Remove-WinEvent
  50. 清理 Windows 安全中心日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-SecurityCenter/Operational" | Remove-WinEvent
  51. 清理 Windows 虚拟化日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-Hyper-V-Worker-Admin/Operational" | Remove-WinEvent
  52. 清理 Windows 虚拟磁盘服务日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-VirtualDiskService/Operational" | Remove-WinEvent
  53. 清理 Windows 网络连接管理器日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-NetworkConnectionBroker/Operational" | Remove-WinEvent
  54. 清理 Windows 安全日志

    powershellCopy Code
    Get-WinEvent -LogName "Security" | Remove-WinEvent
  55. 清理 Windows 自动更新日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-WindowsUpdateClient/Operational" | Remove-WinEvent
  56. 清理 Windows 远程桌面服务日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-TerminalServices-LocalSessionManager/Operational" | Remove-WinEvent
  57. 清理 Windows 应用程序组件日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-AppModel-State/Operational" | Remove-WinEvent
  58. 清理 Windows 组件服务日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-Com/Operational" | Remove-WinEvent
  59. 清理 Windows 启动日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-Kernel-Boot/Operational" | Remove-WinEvent
  60. 清理 Windows 容器日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-Containers/Operational" | Remove-WinEvent
  61. 清理 Windows 定时任务日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-TaskScheduler/Operational" | Remove-WinEvent
  62. 清理 Windows 设备健康状况日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-DeviceHealth-Attestation/Operational" | Remove-WinEvent
  63. 清理 Windows 系统故障排除日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-Diagnosis-DPS/Operational" | Remove-WinEvent
  64. 清理 Windows 文件共享服务日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-SMBServer/Operational" | Remove-WinEvent
  65. 清理 Windows 进程活动日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-ProcessCreation/Operational" | Remove-WinEvent
  66. 清理 Windows 任务栏通知区域日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-Shell-Core/Operational" | Remove-WinEvent
  67. 清理 Windows 存储空间日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-StorageSpaces-Driver/Operational" | Remove-WinEvent
  68. 清理 Windows 证书服务日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-CertificateServices-Client-Lifecycle-System/Operational" | Remove-WinEvent
  69. 清理 Windows 移动设备管理日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-Mobile-Broadband-Experience/Operational" | Remove-WinEvent
  70. 清理 Windows 系统恢复日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-SystemRestore/Operational" | Remove-WinEvent
  71. 清理 Windows 内核事件追踪日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-Kernel-EventTracing/Operational" | Remove-WinEvent
  72. 清理 Windows 安全审计日志

    powershellCopy Code
    Get-WinEvent -LogName "Security" | Remove-WinEvent
  73. 清理 Windows 应用程序错误日志

    powershellCopy Code
    Get-WinEvent -LogName "Application" | Remove-WinEvent
  74. 清理 Windows 系统错误日志

    powershellCopy Code
    Get-WinEvent -LogName "System" | Remove-WinEvent
  75. 清理 Windows PowerShell 日志

    powershellCopy Code
    Get-WinEvent -LogName "Windows PowerShell" | Remove-WinEvent
  76. 清理 Windows DNS 审计日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-DNS-Client/Operational" | Remove-WinEvent
  77. 清理 Windows DHCP 审计日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-DHCP-Client/Operational" | Remove-WinEvent
  78. 清理 Windows 文件复制服务日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-DfsSvc/Operational" | Remove-WinEvent
  79. 清理 Windows 转发事件跟踪日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-EventForwarding/Operational" | Remove-WinEvent
  80. 清理 Windows 远程桌面服务日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-TerminalServices-RemoteConnectionManager/Operational" | Remove-WinEvent
  81. 清理 Windows 文件服务器资源管理器日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-SRMSVC/Operational" | Remove-WinEvent
  82. 清理 Windows 存储池日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-StorageSpaces-ManagementAgent/Operational" | Remove-WinEvent
  83. 清理 Windows 扫描管理器日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-ScanManagement/Operational" | Remove-WinEvent
  84. 清理 Windows 分析引擎日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-Resource-Exhaustion-Detector/Operational" | Remove-WinEvent
  85. 清理 Windows 网络连接日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-TCP/IP/Operational" | Remove-WinEvent
  86. 清理 Windows 网络驱动程序日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-NDIS/Operational" | Remove-WinEvent
  87. 清理 Windows 文件保护日志

    powershellCopy Code
    Get-WinEvent -LogName "Microsoft-Windows-Wininit/Operational" | Remove-WinEvent
    1. 清理 Windows 文件复制服务调试日志

      powershellCopy Code
      Get-WinEvent -LogName "Microsoft-Windows-DfsSvc/Debug" | Remove-WinEvent
    2. 清理 Windows 远程管理服务日志

      powershellCopy Code
      Get-WinEvent -LogName "Microsoft-Windows-TerminalServices-LocalSessionManager/Operational" | Remove-WinEvent
    3. 清理 Windows 容器日志

      powershellCopy Code
      Get-WinEvent -LogName "Microsoft-Windows-Containers/Operational" | Remove-WinEvent
    4. 清理 Windows 集群日志

    ```powershell
    Get-WinEvent -LogName "Microsoft-Windows-FailoverClustering/Operational" | Remove-WinEvent
    ```
    1. 清理 Windows 数据保护日志
    ```powershell
    Get-WinEvent -LogName "Microsoft-Windows-DataProtection-Server/Operational" | Remove-WinEvent
    ```
    1. 清理 Windows 数据保护日志
    ```powershell
    Get-WinEvent -LogName "Microsoft-Windows-DataProtection-Client/Operational" | Remove-WinEvent
    ```
    1. 清理 Windows 数据库引擎服务日志
    ```powershell
    Get-WinEvent -LogName "Microsoft-Windows-SQLEngine/Operational" | Remove-WinEvent
    ```

 

标签:powershellCopy,Code,WinEvent,Get,Windows,清理,Remove,磁盘空间
From: https://www.cnblogs.com/suv789/p/18288074

相关文章

  • Windows如何查看端口是否占用,并结束端口进程
    需求与问题:前后端配置了跨域操作,但是仍然报错,可以考虑端口被两个程序占用,找不到正确端口或者后端接口书写是否规范,特别是利用PythonFlask书写时要保证缩进是否正确!Windows操作系统中,查看端口是否占用并结束占用端口的程序是一个常见的操作,特别是在进行网络配置或软件安装时。......
  • 安装MySQL(Windows10和Linux CentOS7) 很详细的
    Windows10下安装MySQL1.下载MySQL官网下载MySQL:https://www.mysql.com/进入官网点击DOWNLOADS下滑点击MySQLCommunity(GPL)Downloads点击MySQLInstallerforWindows选择版本下载这里就不需要登录注册了,直接下载2.安装MySQL找到下载的文件双击之后选择Se......
  • windows下C++配置googletest过程记录
    文章目录下载googletest将googletest解压到项目目录并创建build文件夹编译googletest在项目的CMakeLists.txt文件中添加相关依赖编写测试并执行参考下载googletestReleasev1.14.0·google/googletest·GitHub将googletest解压到项目目录并创建build文件夹在g......
  • Windows防火墙 日志 自定义 以记录被丢弃的数据包和成功的连接日志。以下是一个示例.r
     配置注册表,以记录被丢弃的数据包和成功的连接日志 WindowsRegistryEditorVersion5.00;WindowsDefender防火墙日志记录设置[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy];以下是针对不同配置文件的设置,例如......
  • 关于Windows防火墙的漏洞,具体信息可能随着时间和操作系统版本的更新而变化。以下是一
    Windows防火墙,特别是WindowsDefender防火墙,是Windows操作系统中用于保护计算机免受网络攻击的关键组件。然而,像任何其他安全系统一样,Windows防火墙也可能存在漏洞或安全问题。以下是一些可能涉及Windows防火墙的具体漏洞或安全问题的讨论:1.默认配置和设置不当默认设置不安全:W......
  • 编写 PowerShell 脚本来管理 Windows 防火墙可以帮助自动化配置和监控网络安全设置。
    编写PowerShell脚本来管理Windows防火墙可以帮助自动化配置和监控网络安全设置。以下是一个简单的大纲,涵盖了管理Windows防火墙的主要方面:1.导入模块和设置变量导入 NetSecurity 模块以访问防火墙cmdlet。设置需要使用的变量,如规则名称、端口号等。2.查询和列出......
  • MinGW GCC Windows下编译libmodbus
    最近项目从MSVC切换到GCC,libmodbus官网没提供MinGW下GCC如何编译,官网推荐在类UNIX环境下MSYS下编译,个人更偏向直接拿源文件编译。编译libmodbus版本:libmodbus-3.1.10GCC编译器版本: 5.3.0(i686-posix-dwarf-rev0,BuiltbyMinGW-W64project)CMake版本: 3.29.0在随笔最......
  • 在 Windows 中,你可以通过修改注册表来调整系统对于同时打开 SYN 半连接数目的限制。这
    在Windows中,你可以通过修改注册表来调整系统对于同时打开SYN半连接数目的限制。这个限制通常被用来防范SYN攻击,但有时候需要根据特定的网络环境和需求进行调整。以下是在注册表中修改SYN半连接数目限制的步骤:打开注册表编辑器:按下Win+R组合键打开运行窗口。......
  • 在 Windows 操作系统中,HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tc
    在Windows操作系统中,HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters下的两个重要参数控制着TCP/IP协议栈的行为。这些参数可以通过注册表来配置,影响网络连接和端口资源的管理。1.MaxUserPort路径: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSe......
  • windows下,用PowerShell安装fnm,并安装Node.js步骤
    1#installsfnm(FastNodeManager)/安装fnm2wingetinstallSchniz.fnm3#重新开启powershell4#!不确定是否需要此步骤!5$profile6#!不确定是否需要此步骤!按照上面的输出,创建缺失的文件夹7#创建$profile文件:粘贴到powershell后,按回车8if(!(Test-P......