EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials PowerShell Tutorial PowerShell Run Command
Secondary Sidebar
PowerShell Tutorial
  • cmdlet
    • PowerShell Wait
    • PowerShell Match
    • cmdlets in PowerShell
    • Start PowerShell from cmd
    • Add-Content in PowerShell
    • Get Help in PowerShell
    • PowerShell Copy-Item
    • PowerShell Remove-Item
    • PowerShell Move-Item
    • Get Command in PowerShell
    • PowerShell Run Command
    • Windows PowerShell ISE
    • Windows Powershell Commands
    • WinRM PowerShell
    • PowerShell Date
    • Powershell Write-Host
    • PowerShell Get-ChildItem
    • PowerShell Sort-Object
    • PowerShell Where Object
    • PowerShell Set-Content
    • PowerShell Set-Location
    • PowerShell Invoke-Command
    • PowerShell Invoke-Webrequest
    • PowerShell Get-Location
    • PowerShell Get-Date
    • PowerShell Get-Service
    • PowerShell Test-Path
    • Powershell Module Path
    • PowerShell Out-File
    • PowerShell if File Exists
    • Powershell Copy File
    • PowerShell Delete File
    • PowerShell New-Item
    • PowerShell Rename-Item
    • PowerShell ComputerName
    • PowerShell Get-Content
    • PowerShell Get-Item
    • PowerShell Get-ADUser
    • PowerShell Grep
    • PowerShell Concatenate String
    • PowerShell Get-Process
    • PowerShell Count
    • PowerShell pause
  • Basics
    • PowerShell Restart Service
    • PowerShell comment
    • PowerShell Map Network Drive
    • PowerShell Append to File
    • PowerShell print
    • What is PowerShell
    • Uses Of Powershell
    • PowerShell Empire
    • PowerShell Parameter
    • PowerShell Stop Service
    • PowerShell Versions
    • How To Install PowerShell
    • PowerShell uninstall module
    • How to Use PowerShell?
    • PowerShell Logging
    • PowerShell Tools
    • PowerShell Commands
    • PowerShell Version Command
    • PowerShell Administrator
    • PowerShell Modules
    • PowerShell Registry
    • PowerShell block Comment
    • PowerShell Verbs
    • PowerShell list
    • PowerShell add user to group
    • PowerShell Write to Console
    • Variable in PowerShell
    • PowerShell New Line
    • PowerShell prompt for input
    • PowerShell File Extension
    • Powershell Remotesigned
    • PowerShell Write to File
    • PowerShell Ping
    • PowerShell wget
    • PowerShell Global variable
    • PowerShell Get-ADGroup
    • Array in PowerShell
    • PowerShell Multidimensional Array
    • PowerShell Array of Strings
    • PowerShell? join array
    • Useful PowerShell Scripts
    • String in PowerShell
    • PowerShell Switch Statement
    • PowerShell Function Parameters
    • PowerShell vs PowerShell ISE
    • PowerShell test-connection
    • PowerShell Test-NetConnection
    • PowerShell GUI
    • PowerShell Variable in String
    • PowerShell Active Directory
  • Variables
    • PowerShell Variables
    • PowerShell Environment Variables
    • PowerShell set environment variable
    • Hashtable in PowerShell
    • Set Variable in PowerShell
  • Operators
    • PowerShell Operators
    • Comparison Operators in PowerShell
    • Logical Operators in PowerShell
    • PowerShell Boolean
    • PowerShell Like Operator
  • Control Statements
    • If Statement in PowerShell
    • If Else in PowerShell
    • Else If in PowerShell
    • Loops in PowerShell
    • For loop in PowerShell
    • PowerShell While Loop
    • PowerShell do while
    • PowerShell Loop through Array
    • PowerShell add to array
    • PowerShell ForEach Loop
    • PowerShell Break
    • PowerShell Continue
    • Switch Case in PowerShell
    • PowerShell If-Not
    • Try-catch in PowerShell
  • Functions
    • PowerShell Functions
    • PowerShell String Functions
    • powershell nslookup
    • PowerShell here string
    • PowerShell Wildcards
    • Regex in PowerShell
    • PowerShell not like
    • PowerShell Filter
    • PowerShell Sleep
    • PowerShell where
    • PowerShell join string
    • PowerShell Exit
    • PowerShell null
    • PowerShell Dictionary
    • PowerShell Location
    • PowerShell Start-Service
    • PowerShell is not digitally signed
    • PowerShell Uptime
    • PowerShell Create Directory
    • PowerShell Trim
    • PowerShell Join-Path
    • PowerShell Execution Policy
    • PowerShell SubString
    • PowerShell Format Table
    • PowerShell Import Module
    • PowerShell ForEach Object
    • PowerShell Alias
    • PowerShell Scheduled Task
    • PowerShell Convert String to Date
    • PowerShell Split String
    • PowerShell Multiline String
    • PowerShell MultiLine Comment
    • PowerShell Rename Folder
    • PowerShell Delete Folder
    • PowerShell String Replace
    • PowerShell join
    • PowerShell xcopy
    • PowerShell Base64
    • PowerShell Tail
    • PowerShell User List
    • PowerShell remove User from group
    • PowerShell JSON Format
    • PowerShell Send Mail
    • PowerShell Convert to String
    • PowerShell Start-Process
    • PowerShell change directory
    • PowerShell Open File
    • PowerShell Batch File
    • PowerShell ZIP
    • PowerShell unzip
    • PowerShell XML
    • PowerShell XML Parsing
    • Remote PowerShell
    • PowerShell Escape Character
    • PowerShell scriptblock
    • PowerShell Executable Location
    • PowerShell Import-CSV?
    • PowerShell Export CSV
  • Interview Questions
    • PowerShell Interview Questions

Related Courses

Shell Scripting Course

All in One Data Science Courses

Data Visualization Courses

PowerShell Run Command

By Priya PedamkarPriya Pedamkar

PowerShell-Run-Command

Introduction to PowerShell Run Command

PowerShell Run Commands this article is all about the PowerShell Run Commands which every IT Professional and System Administrator should be aware of.

  • PowerShell Run Commands are essential to know about for getting your things done seamlessly and smoothly through PowerShell.
  • PowerShell commands are referred to as cmdlets (Command-Let).
  • These commands can be used by the users to perform various management tasks from monitoring to managing servers, testing and debugging scripts and other administrative tasks.

Basic PowerShell Run Commands

Let us walk through some of the very basic and important PowerShell commands to understand their uses in carrying out various tasks.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (85,992 ratings)

These commands are helpful in retrieving information in various formats from different data sources like file or folder system, registries, etc.

1. Get-Help

  1. This PowerShell command is the very basic command every Administrator or developer should be aware of.
  2. It is helpful in getting help with other commands, in simple terms, to get the information about other commands.

The syntax for this command is:

Get-Help

Output:

Windows will display the entire information about how to get help from PowerShell with other commands.

Get-Help

Let us see how this command works for a particular command or cmdlet for which we want information.

Get-Help Get-Process

Output:

The above command displays the complete information about the cmdlet “Get-Process” with full command syntax.

powershell-run-command

To view any help document, you can type Get-Help followed by the exact name of the help file.

For example,

Get-Help about_should

Should is a help file and the above syntax is for getting the information about this help file.

Output:

The file’s content with a complete description along with examples get displayed on the screen.

powershell-run-command

2. Get-Command

This cmdlet is used to get the full list of commands (types Alias, Function and Script) available to you for use in the current session.

The syntax for this cmdlet is  VERB-NOUN

where,

VERB refers to Get, Set, Add, Clear, Read and Write

NOUN refers to files, servers, storage and various other items in the system. 

Example:

Get-Command

Output:

powershell-run-command

  • Specifically, if you want to get the list of only Alias type, the cmdlet would be

Get-Command -CommandType Alias

  • For Function type, the cmdlet would be

Get-Command -CommandType Function

  • For Scripts, the cmdlet would be

Get-Command -CommandType Script

3. Get-Execution Policy

  • Microsoft by default restricts users from executing scripts in PowerShell environment for security reasons.
  • In order to use scripting, users need to change the default setting or default policy.

For this, one should first be familiar with the execution policies for running the scripts.  The cmdlet for this is given below

Get-ExecutionPolicy -List

Output:

This displays a list of execution policies with their scopes.

powershell run command

This list shows that for Local Machine, Execution Policy has been changed to Unrestricted.

4. Get-Process

  • This cmdlet displays a list of all currently running processes on the local machine If no parameter is passed, this cmdlet will return all the active processes on the system.

Example:

Get-Process

Output: 

powershell-run-command

  • For a particular process, you can specify process name or process Ids (Id).

Example:

Get-Process -id 0

This cmdlet will display the process with Id 0, that is, Idle process.

Output:

Process Name

Note: If there is no process with the specified Id, it means that either the Id is wrong or that particular process has exited.

For example,

The below cmdlet searches for a process with Id 99.

Get-Process -id 99

Output:

This throws an error stating that no process was found with Id 99.

Stating process

  • You can use “Stop-Process” to stop a running process by specifying its Name or Id.

For example,

There is a process “Calculator” running in your local machine.

Get-Process -ProcessName Calculator

Get-Process

To stop this process, you can type the following cmdlet

Stop-Process -ProcessName Calculator

This will terminate the running instance of Calculator.

5. Get-Service

  • This cmdlet returns all the services on your local machine whether running or stopped.
  • If no parameter is passed with this cmdlet, all the services of your local machines are returned.

Example:

Get-Service

Output:

All the services, Running and Stopped, are returned.

powershell-run-command

To get the services that are running, type in the following cmdlet.

Get-Service | Where-Object {$_.Status –eq “Running”}

Output:

powershell-run-command

You can also get the properties of the service using Get-Member cmdlet.

Get-Service | Get-Member

Output:

This cmdlet displays the properties and methods of the objects generated as an output of Get-Service cmdlet.

(|) pipe operator’s role here is to send the output of Get-Service cmdlet to Get-Member cmdlet.

6. Where-Object

  • It is used to select objects having particular values from a list of objects passed to it.

Example:

Get-Service | Where-Object {$_.Status -eq 'Running'}

This cmdlet will simply take a collection of objects and will pass it to the pipe operator for filtering to return a list of services whose status is “Running”.

7. ConvertTo-HTML

  • This cmdlet is helpful when you want to create a report out of the information about a system.
  • To do this, simply use the pipe(|) operator to provide the output from one command to ConvertTo-HTML.
  • ConvertTo-HTML basically converts Microsoft .NET Framework objects into HTML to be displayed in a web browser.

For example,

You can create a web page and display the PowerShell aliases.

Get-Alias | ConvertTo-Html | Out-File Display_Alias.htm
invoke-item Display_Alias.htm

This will display all the aliases on a web page.

  • You can also export the information in a .csv file

Get-Alias | ConvertTo-Html > Display_Alias.htm
invoke-item Display_Alias.htm

8. Get-EventLog

  • Using this cmdlet, you can get event logs from your local computer as well as a remote computer.
  • To get a list of event logs in your local system

Get-EventLog -List

Output:

Get eventlog list

Conclusion

  • This article walked you through the very basic but very essential commands to work in PowerShell.
  • Here, we tried to understand the purpose and uses of various PowerShell commands.
  • These are extremely helpful for monitoring and troubleshooting purposes as well as managing various administrative tasks.
  • PowerShell commands are all about cmdlets which are easy to remember and execute.
  • Once you get the hold of at least basic PowerShell commands, you can make the most out of the PowerShell as it will massively simplify your daily manual tasks.

Recommended Articles

This is a guide to PowerShell Run Command. Here we discuss the Basic PowerShell Run Commands along with the respective examples and the outputs. You can also go through our other suggested articles to learn more –

  1. Add-Content in PowerShell
  2. PowerShell Date with Examples
  3. Examples and Parameters of PowerShell Out-File
  4. PowerShell Alias | How to Access and Create?
  5. PowerShell While Loop
Popular Course in this category
Programming Languages Training (41 Courses, 13+ Projects, 4 Quizzes)
  41 Online Courses |  13 Hands-on Projects |  322+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Shell Scripting Training (4 Courses, 1 Project)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
Data Visualization Training (15 Courses, 5+ Projects)4.7
1 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more