Posts

Showing posts from March, 2021

10 essential Windows keyboard shortcuts that will make you forget your mouse

Image
Basic Windows keyboard shortcuts Ctrl+Z: Undo No matter what program you’re running, Ctrl+Z will roll back your last action. Whether you’ve just overwritten an entire paragraph in Microsoft Word or deleted a file you didn’t mean to, this one is an absolute lifesaver. Ctrl+W: Close Another shortcut that works just about everywhere, Ctrl+W will close down whatever you’re viewing. Shut that File Explorer window, browser tab. Ctrl+A: Select all This command lets you highlight all the text in a document or select all the files in a folder. Hitting Ctrl+A can save you time you’d otherwise spend clicking and dragging your mouse. Windows shortcuts for navigation Win+D: Show or hide the desktop This keyboard combo minimizes all your open windows, bringing your home screen into view. Win+Tab: Open the Task view This shortcut lets you switch apps. Win+M: Minimize all windows. This shortcut lets you minimize all open apps. Ctrl+Esc: Open the Start menu If you’re using a keyboard that doesn’t have

Error Handling in PowerShell

Image
A good practice while working on any script is to have a mechanism for error handling. Though it may take a little bit of additional time, its rewards are priceless. Before moving to Error handling in PowerShell, first go through what type of errors we may encounter. Error Types There are two types of errors that can be occurred during script execution.  Terminating  Non-terminating  As the name implies, terminating error will stop the program from further execution, whereas a non-terminating error will not stop the execution. An example of terminating error would be a syntax error whereas an example of non-terminating error would be file/path not found. Terminating errors can be caught and handled while Non-terminating errors cannot be caught by try-catch block. Examples:  Terminating error: Script execution halted when error occurred. Non-terminating error:  Write-Host "Still running" executed even after error occurred. Convert Non-terminating errors into Terminating       

How to generate a GUID in PowerShell

Image
 If you ever need a unique id in your script, you can create GUID (globally unique identifier) In PowerShell 4.0 and earlier you can use [guid] class with its static method. In PowerShell 5.0 and later, you can use New-Guid cmdlet: You can use Get-Member to know its object type. You can also store GUID into a variable like below If you want to get GUID as string, use ToString  method or Guid  property. Both return output of string type, you can verify this using Get-Member .

How to Clean Up PowerShell Script Variables without Restarting PowerShell ISE

In this tutorial, we will see how to clean up variables and modules in PowerShell ISE without restart. PowerShell ISE and Variables values PowerShell ISE does not automatically cleanup it’s variable between manual runs of a script. Due to this, results doesn't came out as we expected. Run below command to clear all variables stored in the session. Remove-Variable * -ErrorAction SilentlyContinue This will take care of clearing all stored variables so we can be sure, script will not inherit any value from a previous run. PowerShell ISE Errors and ModulesPermalink Issue which we face due variable retains value from previous run, can happen with Error buffer also, which can be cleared with the below command. $error .Clear() We can also remove any module loaded by our script with the below command Remove-Module *