Network Applications (QHO443) - Week 10
Prepared by Babashaheer
Complete solutions with explanations
Read-Host prompts the user and stores their inputGet-Service -Name $serviceName retrieves the service information$service.Status accesses the Status property-eq "Running" checks if the status equals "Running"Get-ChildItem *.txt gets all files ending with .txt$txtFiles variable.Count property returns the number of itemsWrite-Output "Found $((Get-ChildItem *.txt).Count) text files in this directory"
Sort-Object CPU -Descending puts highest CPU firstSelect-Object -First 1 gets only the top process$topProcess.CPU accesses the CPU property-gt 50 checks if greater than 50$($topProcess.ProcessName) uses subexpression for clean output
Read-Host gets password input from user$password.Length -ge 12 checks if 12+ characters$password -match '\d' checks if contains a digit (0-9)-and operator ensures BOTH conditions are trueRead-Host -AsSecureString to hide input, though checking requirements becomes more complex.
Get-Service retrieves all servicesWhere-Object Status -eq 'Running' filters to running onlySelect-Object -ExpandProperty Name extracts just the names (not table format)Sort-Object sorts alphabeticallyGet-Service | Where-Object Status -eq 'Running' | Select-Object -ExpandProperty Name | Sort-Object
Get-Date -Format creates formatted timestamp.Count property gives totals for each$(...) subexpression syntax in strings for complex variablesWrite-Output statements build formatted report
Read-Host gets size threshold from user$sizeMB * 1MB converts MB to bytes (1MB = 1048576 bytes)Where-Object Length -gt $sizeBytes filters by file sizeif ($largeFiles.Count -gt 0) checks if any files foundforeach loop iterates through each file[math]::Round() rounds to 1 decimal place for clean display`n adds blank line for formatting
@('Service1', 'Service2') creates an array of service names$runningCount = 0 initializes counter variableforeach ($svcName in $criticalServices) loops through arrayGet-Service -Name $svcName gets each service in turn$runningCount++ increments counter for running services