{"id":636,"date":"2024-10-22T11:29:24","date_gmt":"2024-10-22T08:29:24","guid":{"rendered":"https:\/\/itgen.itbumper.com\/?page_id=636"},"modified":"2024-10-22T11:33:19","modified_gmt":"2024-10-22T08:33:19","slug":"windows-cleaning-script-ps","status":"publish","type":"page","link":"https:\/\/itgen.itbumper.com\/?page_id=636","title":{"rendered":"Windows cleaning script (PS)"},"content":{"rendered":"\n\n<p>An example of the windows cleaning script.<\/p>\n<p>clean_windows_v1_1.ps1<\/p>\n<p>To allow run scripts, use it if needed.<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nSet-ExecutionPolicy RemoteSigned\n<\/pre><\/div>\n\n<p>To run the script in PowerShell:<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n.\\clean_windows_v1_1.ps1\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# Powershell\n# Script ver 1.1\n# Stop all update services\nStop-Service -Name wuauserv -Force\nStop-Service -Name bits -Force\nStop-Service -Name cryptsvc -Force\n\n# Cleaning Windows update cache\nWrite-Host &quot;Clean Windows update cache ...&quot;\nRemove-Item -Path &quot;C:\\Windows\\SoftwareDistribution\\Download\\*&quot; -Recurse -Force\nRemove-Item -Path &quot;C:\\Windows\\SoftwareDistribution\\DataStore\\*&quot; -Recurse -Force\n\n# Start update services\nStart-Service -Name wuauserv\nStart-Service -Name bits\nStart-Service -Name cryptsvc\nWrite-Host &quot;Update services have been started.&quot;\n\n# Cleaning the system`s temp files\nWrite-Host &quot;Cleaning the system`s temp files ...&quot;\nRemove-Item -Path &quot;C:\\Windows\\Temp\\*&quot; -Recurse -Force -ErrorAction SilentlyContinue\n\n# Cleaning all users temp files\nWrite-Host &quot;Cleaning all users temp files ...&quot;\n$users = Get-ChildItem 'C:\\Users' | Where-Object { $_.PSIsContainer }\nforeach ($user in $users) {\n    $tempPath = &quot;$($user.FullName)\\AppData\\Local\\Temp\\&quot;\n    if (Test-Path $tempPath) {\n        Remove-Item -Path &quot;$tempPath\\*&quot; -Recurse -Force -ErrorAction SilentlyContinue\n    }\n}\n\n# Deleting PDF files older than 60 days in the D:\\doc\\pdf\nWrite-Host &quot;Deleting PDF files older than 60 days in the D:\\doc\\pdf ...&quot;\n$pathToPDFs = &quot;D:\\doc\\pdf\\&quot;\n$oldFiles = Get-ChildItem -Path $pathToPDFs -Filter *.pdf | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-60) }\nforeach ($file in $oldFiles) {\n    Remove-Item -Path $file.FullName -Force\n}\n\nWrite-Host &quot;Cleaning complete.&quot;\n\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>An example of the windows cleaning script. clean_windows_v1_1.ps1 To allow run scripts, use it if needed. To run the script in PowerShell:<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/pages\/636"}],"collection":[{"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=636"}],"version-history":[{"count":2,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/pages\/636\/revisions"}],"predecessor-version":[{"id":640,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/pages\/636\/revisions\/640"}],"wp:attachment":[{"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=636"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=636"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=636"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}