Improving DEX: Step Four – Maintenance

Trying to keep desktop computers running reliably and fast requires maintenance beyond patching. In this blog, I will discuss some of my favorite maintenance tasks that can be performed with Edge DX.

This blog is just one in a four-part series called Improving the Digital Employee Experience:

Try Edge DX free with the 50-User VIP Pack.

As discussed in previous blogs, we use Edge DX scripts to help troubleshoot and remediate Windows, macOS, and Linux. This blog will discuss how scripts can be essential for maintaining desktop computers for years to maintain performance and reliability.

Scripts can be set to run automatically in many different ways. For maintenance-type tasks, you can select a trigger to run a script, such as Short Intervals (120 seconds), Long Intervals (600 seconds), Once Per Day, Process or Application Start, Logon, etc. In Figure 1, you can see some of the option configurations to trigger a script.

Figure 1, Edge DX Script Triggers

Since scripts can do almost any maintenance task on a desktop computer, we also know that scripts can be started based on time, boot-up, etc. So, here are some of my favorite maintenance actions.

  • Windows Storage Sence.
    • Windows Storage Sense is a built-in feature in Microsoft Windows 10 and Windows 11 that helps you manage and optimize your computer’s storage space. Its primary purpose is to free up space on your hard drive by automatically deleting unnecessary and temporary files. By default, Windows Storage Sense is disabled, and when enabled, it will only run when the hard disk is full. Run this PowerShell script in “Custom-Action User” to enable Windows Storage Sence and configure it to run once a month.
    • Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy" -Name "01" -Value 1
      Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy" -Name "2048" -Value 30
  • Check CPU temp.
    • An overheated CPU can be a result of many causes. For instance, a process could consume 100% of the CPU, a fan might be broken, or the laptop vents could be clogged. But if we can detect the CPU temp, we can check other areas of interest to determine if the computer needs maintenance.
    • <#
      .SYNOPSIS
      Gets the CPU temperature
      .DESCRIPTION
      Gets the CPU temperature from WMI Class MsAcpi_ThermalZoneTemperature
      .NOTES
      Not all motherboard BIOS software implements Acpi_ThermalZoneTemperature. If the call fails this does not necessarily indicate there is something wrong with the motherboard, it has simply not been implemented.
      28-02-2022: Ton de Vreede
      - Added minimum PS version
      - Added error handling
      #>
      $ErrorActionPreference = 'Stop'
      # Set output encoding to ensure non-ASCII characters are captured
      [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
      # Try get temperature from MsAcpi_ThermalZoneTemperature class
      try {
      	[string]$output = Get-WmiObject -Namespace root/wmi -ClassName MsAcpi_ThermalZoneTemperature -Filter "Active='True' and CurrentTemperature<>2732" -Property InstanceName, CurrentTemperature |
      	Select-Object InstanceName, @{n = 'CurrentTemperatureC'; e = { '{0:n0} C' -f (($_.CurrentTemperature - 2732) / 10.0) } } | ConvertTo-Json
      
      	Write-Output("### SIP DATA BEGINS ###")
      	Write-Output $output
      	Write-Output("### SIP DATA ENDS ###")
      }
      catch {
      	Write-Output("### SIP EVENT BEGINS ###")
      	Write-Output -InputObject 'The temperature could not be retrieved. The motherboard BIOS software has probably not implemented this MsAcpi_ThermalZoneTemperature.'
      	Write-Output("### SIP EVENT ENDS ###")
      }
  • Remove temporary internet files.
    • Deleting temporary internet files can be beneficial in certain situations, and it’s generally considered good practice to perform this cleanup periodically. Here are some scenarios and reasons when and why you might want to delete temporary internet files: Freeing Up Disk Space, Privacy, Security, Performance Improvement, Resolving Browser Issues, Ensuring Up-to-Date Content, and Browser Troubleshooting.
    • # Get the path to the temporary internet files folder
      $ieCachePath = [System.IO.Path]::Combine($env:LOCALAPPDATA, 'Microsoft', 'Windows', 'INetCache')
      # Remove files in the temporary internet files folder
      Remove-Item -Path "$ieCachePath\*" -Force -Recurse
      Write-Host "Temporary internet files deleted successfully."
  • Defrag the hard drive.
    • Defragmenting a hard drive can be beneficial for several reasons. Still, it’s important to note that the need for defragmentation of modern file systems has decreased and is sometimes not recommended for solid-state drives (SSDs).
    • Optimize-Volume -DriveLetter C -ReTrim -Analyze
  • Restore default file associations
    • As programs get added over time, the default file association may get out of company standards. With a simple maintenance script, you can easily re-associate file associations back to whatever you want.
    • # Reset default file associations using dism
      # Define common file types
      $fileTypes = ".txt", ".jpg", ".png", ".pdf"
      # Add more file types as needed
      foreach ($fileType in $fileTypes) {
          $command = "Dism.exe /Online /Import-DefaultAppAssociations:C:\Path\To\DefaultAppAssociations.xml"
          Invoke-Expression -Command $command
      }
      Write-Host "File associations reset to default."
      
  • Repair Windows OS Files
    • System File Checker (SFC) is a built-in Windows utility that allows users to scan and repair corrupted or missing system files on a Windows operating system. The sfc.exe executable is the command-line interface for running the System File Checker tool. When you run sfc /scannow, it initiates a scan of protected system files and attempts to replace incorrect versions with correct Microsoft versions.
    • # Run SFC scan
      function Run-SfcScan {
          try {
              # Start SFC process
              Start-Process -FilePath "sfc.exe" -ArgumentList "/scannow" -Wait -NoNewWindow
              Write-Host "SFC scan completed successfully."
              return $true
          } catch {
              Write-Host "Error running SFC scan: $_"
              return $false
          }
      }
      # Example usage
      Run-SfcScan
      
  • Check Windows registry integrity
    • Checking the Windows registry integrity is essential for several reasons, as the registry plays a crucial role in the Windows operating system’s functionality. Here are some key reasons you might want to check Windows registry integrity: System stability, application performance, malware and security, software installation and uninstallation, Windows updates, driver configuration, system troubleshooting, and preventive maintenance.
    • # Check registry integrity
      function Test-RegistryIntegrity {
          param (
              [string]$registryHive = "HKLM:\System\CurrentControlSet\Control"
          )
          try {
              # Try to access the specified registry key
              Get-Item -LiteralPath $registryHive | Out-Null
              Write-Host "Registry integrity check passed. The specified registry key exists and is accessible."
              return $true
          } catch {
              Write-Host "Registry integrity check failed. Unable to access the specified registry key."
              return $false
          }
      }
      # Example usage
      Test-RegistryIntegrity
  • List auto-start programs.
    • Over time, users may experience many overzealous programs that all want to auto-start, which then leads to consuming unneeded resources and increasing logon times. I like to check and see how many startup apps are executing and if excessive, disable them.
    • # Get a list of startup applications using WMI
      $StartupApps = Get-CimInstance -Namespace "Root\CIMv2" -Class Win32_StartupCommand
      # List the startup applications
      Write-Host "Startup Applications:"
      Write-Output("### SIP EVENT BEGINS ###")
      foreach ($app in $StartupApps) {
          Write-Host "Name: $($app.Name)"
          Write-Host "Command: $($app.Command)"
          Write-Host "Location: $($app.Location)"
          Write-Host "User: $($app.User)"
          Write-Host ""
          Write-Host "------------------"
      }
      	# Set output encoding to ensure non-ASCII characters are captured
      	[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
      
      	# Write output
      	
      	Write-Output $arrPrinters
      	Write-Output("### SIP EVENT ENDS ###")
      	Exit 0
      catch {
      	Write-Output("### SIP EVENT BEGINS ###")
      	Write-Output -InputObject "There was a problem retrieving the printer details for the user:`n$_"
      	Write-Output("### SIP EVENT ENDS ###")
      	Exit 1
      }

Maintenance scripts are easy to implement and powerful to use, and as always, make sure you thoroughly test the scripts before putting them into production.

 

Improving the Digital Employee Experience blog series:

About the author

Jeff Johnson

Jeff is a product marketing manager for ControlUp. He is responsible for evangelizing the Digital Employee Experience on physical endpoints such as Windows, macOS, and Linux. Jeff has spent his career specializing in enterprise strategies for client computing, application delivery, virtualization, and systems management. Jeff was one of the key architects of the Consumerization of IT Strategy for Microsoft, which has redefined how enterprises allow unmanaged devices to access corporate intellectual property.