EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login

How to Use PowerShell?

By Priya PedamkarPriya Pedamkar

Home » Data Science » Data Science Tutorials » PowerShell Tutorial » How to Use PowerShell?

How to Use PowerShell

What is PowerShell?

PowerShell is a Powerful task automation tool provided by Microsoft. Used as a configuration management framework for simplifying the configurations in the Windows ecosystem. It consists of a task-based command-line shell and scripting language.  Designed mainly for system administrators. Helps IT professionals control and automate the administration of Windows Operating System and applications running on Windows. Built on top of the .NET framework and is based on object-oriented standards. cmdlet, a specialized, unique and single-function command-line tool comes into the picture with Windows PowerShell. All the administrative tasks are generally carried out by cmdlets that are capable of implementing certain operations and returning .NET objects.

How to Use PowerShell?

In all the latest versions of Windows, PowerShell can be found pre-installed. We just need to launch it through the given steps:

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

1. Click on the Search icon and find “PowerShell”.

2. We can see several options with PowerShell like

  • Windows PowerShell
  • Windows PowerShell ISE
  • Windows PowerShell (x86)
  • Windows PowerShell ISE (x86)

3. Select Windows PowerShell and right-click to “Run as Administrator”

How to Use PowerShell 1

While searching, apart from Windows PowerShell we get Windows PowerShell ISE as search results.

What is Windows PowerShell ISE?

  • ISE refers to Integrated Scripting Environment.
  • Windows PowerShell ISE makes scripting easier and more robust.
  • It is a host application for Windows PowerShell, where we can run commands, debug our code, identify the issues to fix them and also test the code.
  • PowerShell ISE contains a list of all the cmdlets and common modules required by the system administrators.
  • PowerShell ISE is highly customizable allowing the users to choose color scheme, theme and font while working with scripts.
  • Any script created in this ISE is given .ps1 file extension.

PowerShell cmdlet

  • cmdlet or Command-let is a lightweight command used in the Windows PowerShell environment.
  • cmdlets are created and invoked using PowerShell APIs.
  • These are invoked by it in command prompt.

PowerShell cmdlet Examples

Let us understand how cmdlets work, through a few examples.

Code:

Get-Help

  • This is the first command every administrator should be aware of.
  • It helps you to know about other commands and how to use them.

How to Use PowerShell 2

For example, I want to understand how the Get-Process command works. So, the cmdlet would be

Popular Course in this category
Sale
Programming Languages Training (41 Courses, 13+ Projects, 4 Quizzes)41 Online Courses | 13 Hands-on Projects | 322+ Hours | Verifiable Certificate of Completion | Lifetime Access | 4 Quizzes with Solutions
4.5 (9,067 ratings)
Course Price

View Course

Related Courses
Shell Scripting Training (4 Courses, 1 Project)All in One Data Science Bundle (360+ Courses, 50+ projects)Data Visualization Training (15 Courses, 5+ Projects)

Get-Help -Name Get-Process

How to Use PowerShell 3

Get-Service

On running this cmdlet on the command line, a list of services on the machine is returned.

Get-Service “App*”

This cmdlet returns a list of services that begin with “App”.

How to Use PowerShell 4

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

This cmdlet further filters the list and displays only the services which are running.

How to Use PowerShell 5

Note:

  • $_ refers to the current record in the pipe.
  • It processes each output record returned by Get-Service checks if the status is “Running” and then accordingly filters the results.

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

We can further filter down the list to display only the second column, that is, Name column. This cmdlet will display only the names of the running services.

How to Use PowerShell 6

Get-Command

This cmdlet generates a list of cmdlets and functions installed in the machine.

How to Use PowerShell 7

Note:

  • The syntax for Get-Command is VERB-NOUN.
  • Verbs refer to Get, Set, Add, Clear, Write and Read
  • Nouns refer to files, servers and several other items in the network or system.

PowerShell Scripts

  • PowerShell scripts have file extension as .ps1
  • For security reasons, by default, scripting has been disabled to prevent malicious code from executing in its environment.
  • There are four levels of security available which one can see by running the:

Get-ExecutionPolicy command.

  • Restricted: Default setting where no scripts are allowed to run.
  • All Signed: Scripts will only be allowed to run if they are signed by a trusted developer.
  • Remote Signed: Locally created scripts are allowed to run whereas, remotely created scripts are allowed to run only if they are signed by a trusted developer.
  • Unrestricted: Any script can be run without any restriction.

Execution policy can be set by using the Set-ExecutionPolicy command followed by the name of the policy.

Set-ExecutionPolicy Unrestricted

One can find out the execution policy in use by running the Get-ExecutionPolicy command.

PowerShell Script Examples

There are majorly two ways of creating scripts and executing them.

Example #1 Open a notepad file and write the script directly to Then save this file with a filename with the extension .ps1

  • Write the following line in a notepad file

Write-Host “My First PowerShell Script

  • Then save this file as “ps1”.

“ps1”

  • The script can be called in PowerShell by specifying the filename followed by the location where the file is

.\MyFirstScript.ps1

Example #2 Windows PowerShell ISE is another powerful way of creating PowerShell scripts and executing them. The benefit of using ISE is that it provides an environment to run, test as well as debug the scripts easily.

  • Search for Windows PowerShell ISE and right-click to “Run as administrator”.

Run as administrator

  • Write the following code into the editor and save as “ps1”

Write-Host “My First PowerShell Script”

  • Press F5 to run the code:

How to Use PowerShell 10

Understanding the Use of Variables

1. Open the PowerShell ISE and write the following code

$A = Get-Date
$A

Note:

  • $A is a variable that stores the Date value.
  • $A simply prints the value stored in it.

2. Save the file as “Date.ps1”.

3. Press F5 to execute the script and see the output.

“Date.ps1”.

Understanding the Use of “@”

1. Open the PowerShell ISE and write the following lines.

$array = @{Shape =”Square”;Side=4}
$array

Note:

  • “@” symbol refers to an array.
  • $array is a variable that contains an array.

2. Save the file as “Array.ps1”

3. Press F5 to run the script and see the output.

“Array.ps1”

Conclusion

In this article, we tried to cover almost all the basic ideas on it and hopefully, this will give a clear picture of how to use it. In today’s tech industry, it has become a powerful tool and an ideal choice for IT professionals and administrators due to its great flexibility and contribution to simplifying Management operations. There are numerous tasks one can perform with the help of ps, even those of which you might not be aware. The more you start using it, the more you will start learning the capabilities of this powerful tool.

Recommended Articles

This is a guide to How to Use PowerShell?. Here we discuss what is PowerShell, ISE, and scripts with their examples and use of it. You can also go through our other related articles to learn more –

  1. Machine Learning Software
  2. Importance of Artificial Intelligence
  3. Data Storage Devices
  4. Deep Learning Algorithms

Programming Languages Training (41 Courses, 13+ Projects)

41 Online Courses

13 Hands-on Projects

322+ Hours

Verifiable Certificate of Completion

Lifetime Access

4 Quizzes with Solutions

Learn More

2 Shares
Share
Tweet
Share
Primary Sidebar
PowerShell Tutorial
  • Basics
    • PowerShell comment
    • PowerShell Map Network Drive
    • PowerShell Append to File
    • PowerShell print
    • What is PowerShell
    • Uses Of Powershell
    • PowerShell Versions
    • How To Install PowerShell
    • PowerShell uninstall module
    • How to Use PowerShell?
    • PowerShell Tools
    • PowerShell Commands
    • 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
  • 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
  • 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 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

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

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

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
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.

Let’s Get Started

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

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA Login

Forgot Password?

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

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.

Special Offer - Programming Languages Training (41 Courses, 13+ Projects) Learn More