Question
How to add exception handling in this code of PowerShell? D. Apply exception handling using try-catch for System.OutOfMemoryException Here is the current code: # This
How to add exception handling in this code of PowerShell?
D. Apply exception handling using try-catch for System.OutOfMemoryException
Here is the current code:
# This forces the user to choose a value 1-5, a certain output is returned depending on number choice while($true) { $input= Read-Host "Enter the option 1-5" if ($input -eq 5) { break } switch ( $input ){ # Gets current date and time 1 { $temp= Get-Date $answer = Get-ChildItem | Where-Object { $_.Name -match "[A-Z,a-z,0-9]*[.][l][o][g]" } echo $temp $answer echo $temp $answer >> DailyLog.txt } # Lists files 2 { $answer = Get-ChildItem | Sort-Object -Property name | select name echo $answer echo $answer >> C916contents.txt } # Lists current CPU processing percentage and memory usage 3 { Get-Counter -Counter '\Process(_total)\% Processor Time' -MaxSamples 4 -SampleInterval 5 Get-Counter -Counter '\\desktop-l8dtt4r\physicaldisk(_total)\current disk queue length' -MaxSamples 4 -SampleInterval 5 } # Gets current running procces on PC 4 { Get-Process | Sort-Object -Property cpu } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started