Many developers adore PowerShell, and with good reason: it enhances the Windows Command Prompt, where many of us spend a significant amount of time. It does, however, have a learning curve, but once you’ve mastered the essential instructions, it’ll be productivity on steroids for you.
Cmdlets are the driving force behind PowerShell’s functional capabilities. There are dozens of critical commands that developers should know, ranging from instructions that improve the general Windows experience to ones that are useful for development work. This list has been compiled to serve as a useful reference tool for individuals who are just getting started.
Useful Powershell commands
For anyone using PowerShell, the Get-Help command is crucial, as it provides instant access to the information you need to run and operate with all of the available commands.
Below is the example.
Get-Help [[-Name] ] [-Path ] [-Category ] [-Component ] [-Functionality ] [-Role ] [-Examples] [ ]
Get-Command is a handy reference cmdlet that displays all of the commands that are accessible in your current session.
Output looks like this:
CommandType Name Definition ----------- ---- ---------- Cmdlet Add-Content Add-Content [-Path]
To prevent malicious scripts from running in the PowerShell environment, Microsoft disables scripting by default. Developers, on the other hand, want to be able to build and run scripts, therefore the Set-ExecutionPolicy command lets you adjust the level of security for PowerShell scripts. You can choose from four different security levels:
Restricted: This is the default security level, which prevents the execution of PowerShell scripts. You can only enter commands interactively at this security level.
All Signed: This security level only allows scripts to run if they have been signed by a reliable publisher.
Remote Signed: Any PowerShell scripts produced locally are allowed to run at this security level. Remotely developed scripts are only allowed to run if they have been signed by a recognized publisher.
Unrestricted: As the name implies, the unrestricted security level removes all limitations from the execution policy, allowing all scripts to run.
Similarly, if you’re working in an unfamiliar environment, this command can quickly reveal the current execution policy:
Knowing what services are installed on the system is also beneficial. With the following command, you may quickly get this data:
The output might look like:
Status Name DisplayName ------ ---- ----------- Running AarSvc_4f948d3 Agent Activation Runtime_4f948d3 Running AdobeARMservice Adobe Acrobat Update Service Stopped AJRouter AllJoyn Router Service Stopped ALG Application Layer Gateway Service Running AMD Crash Defen... AMD Crash Defender Service Running AMD External Ev... AMD External Events Utility
If you need to know if a certain service is installed, add the -Name switch to the command and the service’s name, and Windows will display the service’s status. Filtering capabilities can also be used to return a specified subset of currently installed services.
The Get-EventLog cmdlet in PowerShell can really parse your machine’s event logs. There are a number of options accessible. To read a specific log, use the -Log switch followed by the name of the log file. To view the Application log, for example, execute the following command:
Get-EventLog -Log "Application"
Other parameters is Get-Eventlog are:
The output might look like this:
Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName ------- ------ ----- ----- ------ -- -- ----------- 206 13 2696 4320 0.38 13684 6 AdobeIPCBroker 110 8 2008 4224 3816 0 amdfendrsr 371 16 5996 12548 2528 0 AppHelperCap 502 29 20728 14560 1.64 9688 6 ApplicationFrameHost 124 8 1556 2204 5372 0 armsvc
Stop-Process -processname armsvc
Clear-History -Command *help*, *command
get-commad | convertto-html > command.htm
Above cmdlets are some of my special mentions which I use in my day-to-day activities and are also used widely by many Powershell developers. Let me know in the comment section what I have missed in this post so that we can cover it in the coming posts.