Script for System Preventive Maintenance

Overview:

The act of performing regularly scheduled maintenance activities to  prevent unexpected failures of system is called Preventive Maintenance.  It's all about fixing things before they break.

  • Performing preventive maintenance extend the life of your system, reduces downtime,  helps you manage compliance and inspection needs, and prevents costly emergency repairs from occurring.
  •  The Below scripts will help us to clear the temp files, to collect the System information and Task utilization,

# Get system name
$systemName = $env:COMPUTERNAME

# Get operating system information
$os = Get-CimInstance Win32_OperatingSystem
$osName = $os.Caption
$osVersion = $os.Version
$processor1 = Get-WmiObject Win32_Processor

# Get hardware information
$hardware = Get-CimInstance Win32_ComputerSystem
$manufacturer = $hardware.Manufacturer
$model = $hardware.Model
$cpu = Get-CimInstance Win32_Processor | Select-Object -First 1 | Select-Object Name, MaxClockSpeed
$Processor = (Get-WmiObject -ComputerName $Exchserver -Class win32_processor -ErrorAction Stop | Measure-Object -Property LoadPercentage -Average | Select-Object Average).Average
$network = Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object {$_.IPAddress -ne $null}

# Get disk space information
$disk = Get-CimInstance Win32_LogicalDisk -Filter "DeviceID = 'C:'"
$freeSpace = [math]::Round($disk.FreeSpace / 1GB,2)
$totalSpace = [math]::Round($disk.Size / 1GB,2)

# Get d disk space information
$disk1 = Get-CimInstance Win32_LogicalDisk -Filter "DeviceID = 'D:'"
$freeSpace1 = [math]::Round($disk1.FreeSpace / 1GB,2)
$totalSpace1 = [math]::Round($disk1.Size / 1GB,2)

# Get d disk space information
$disk2 = Get-CimInstance Win32_LogicalDisk -Filter "DeviceID = 'E:'"
$freeSpace2 = [math]::Round($disk2.FreeSpace / 1GB,2)
$totalSpace2 = [math]::Round($disk2.Size / 1GB,2)

# Calculate memory usage
$computerName = "localhost"
$memory = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $computerName
$totalMemory = [math]::Round($memory.TotalVisibleMemorySize / 1MB)
$freeMemory = [math]::Round($memory.FreePhysicalMemory / 1MB)
$memoryUsage = [math]::Round(($memory.TotalVisibleMemorySize - $memory.FreePhysicalMemory) / 1MB)

# CPU USAGE
$cpuCounter = "\Processor(_Total)\% Processor Time"
$cpuUsage = (Get-Counter $cpuCounter).CounterSamples[0].CookedValue

# Defragment the C drive
#Defrag.exe C: /U /V

# Generate HTML report
$html = @"
<html>
<head>
    <title>System Information and Performance Report for $systemName</title>
</head>
<body>
    <h1>System Information and Performance Report for $systemName</h1>
    <h2>Operating System</h2>
    <ul>
        <li>OS Name: $osName</li>
        <li>OS Version: $osVersion</li>
        
    </ul>
    <h2>Hardware Information</h2>
    <ul>
        <li>Manufacturer: $manufacturer</li>
        <li>Model: $model</li>
        <li>Total Memory: $totalMemory</li>
         <li>memoryUsed: $memoryUsage GB</li>
         <li>Memory Free : $freeMemory </li>
        <li>CPU: $($cpu.Name) $($cpu.MaxClockSpeed) MHz</li>
    </ul>
    <h2>Disk Space</h2>
    <ul>
         <li> C Drive </li>    
        <li>Total Space C: $totalSpace GB</li>
        <li>Free Space C: $freeSpace GB</li>
         <br>
         <li>  D Drive </li>
        <li>Total Space D: $totalSpace1 GB</li>
        <li>Free SpaceD: $freeSpace1 GB</li>
        <br>
        <li> E Drive</li>
        <li>Total Space E: $totalSpace2 GB</li>
        <li>Free Space E: $freeSpace2 GB</li>
    </ul>
    
    <h2>CPU USAGE</h2
     <p> CPU USAGE : $cpuUsage.</p>
    
    <h2>Temporary Files</h2>
    <p>Temporary files have been cleared.</p>
    <h2>Prefetch Files</h2>
    <p>Prefetch files have been cleared.</p>
    <h2>Defragmentation</h2>
    <p>The C drive has been defragmented.</p>
</body>
</html>
"@

# Save the HTML report
$html | Out-File -FilePath "$systemName.html" -Encoding UTF8

Follow Us On

Registered Office

CHG IT CONSULTANCY PVT LTD

STPI Technology Incubation Centre,
2nd Floor, No.5, Rajiv Gandhi Salai,
Taramani, Chennai – 600113,
Tamil Nadu, INDIA

Parent Office

CIC Corporation

2-16-4 Dogenzaka, Shibuya-ku,
Nomura Real Estate,
Shibuya Dogenzaka Building,
Tokyo 150-0043, JAPAN

  +81 03-3496-1571
AboutUs

CHG IT Consultancy Pvt. Ltd. is a subsidiary of CIC Holdings Co. Ltd. Japan. Our company is focused on IT related solutions to reap the benefits of global popularity of Software Industry.

Registered Office
CHG IT CONSULTANCY PVT LTD

STPI Technology Incubation Centre,
2nd Floor, No.5, Rajiv Gandhi Salai,
Taramani, Chennai – 600113,
Tamil Nadu, INDIA

CIC Corporation

2-16-4 Dogenzaka, Shibuya-ku,
Nomura Real Estate,
Shibuya Dogenzaka Building,
Tokyo 150-0043, JAPAN

+81 03-3496-1571