Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions

Question

What could Tele Maker have done to prevent this disaster?

Answered: 1 week ago

Question

Choose an appropriate organizational pattern for your speech

Answered: 1 week ago

Question

Writing a Strong Conclusion

Answered: 1 week ago