2.6 - פרויקט - פתרון
# Define a function to retrieve information from the local computer
function Get-ComputerInfo {
try {
# Retrieve information about the computer
$computerInfo = Get-WmiObject -Class Win32_OperatingSystem
$processorInfo = Get-WmiObject -Class Win32_Processor
$memoryInfo = Get-WmiObject -Class Win32_ComputerSystem
# Display the information
$osName = $computerInfo.Caption
$osVersion = $computerInfo.Version
$ram = [math]::round($memoryInfo.TotalPhysicalMemory / 1GB, 2) # Convert RAM to GB
$cpuCount = $processorInfo.Count
Write-Host "Computer name: $(hostname)"
Write-Host "Operating system: $osName"
Write-Host "Operating system version: $osVersion"
Write-Host "RAM: $ram GB"
Write-Host "Number of CPUs: $cpuCount"
} catch {
Write-Host "Error retrieving information. Please make sure the WMI connection is active." -ForegroundColor Red
}
}
# Function to refresh the information every 10 seconds
function Monitor-ComputerStatus {
while ($true) {
# Retrieve the information again each time
Clear-Host
Get-ComputerInfo
# Wait 10 seconds before the next update
Start-Sleep -Seconds 10
}
}
# Call the function that performs the monitoring
Monitor-ComputerStatus