in

WindowsWindows Loving ItLoving It

PowerShell File on Windows 10 NotePad and ISE [2020]

The PowerShell files is the best way to save scripts and reuse it. We can create PowerShell file with NotePad and ISE.

PowerShell files

If you are new to PowerShell you can use this article to create your first PowerShell file that actually does something.

This is article will work for the latest Windows 10 PowerShell.

Jump to:

Windows 10 PowerShell is a command-line tool that is used for scripting.  We can use PowerShell to change settings, automate tasks and more.

What is a PowerShell Script?

A PowerShell script file is just a set of scripts saved to a file with a file extension ‘.ps1‘.  But we will not be able to run a PowerShell script by just double-clicking it.  We need to set the correct execution policy for that.  Before we get to that, let us see how to create a PowerShell file.

How to Create a PowerShell Script file in NotePad?

We will write a PowerShell script in a notepad file using the instructions given below.  We will make a script that will fetch all the services that are stopped.  We will do that by the below script.

get-service |? status -eq “stopped”
stopped service command
stopped service command

If we execute that script on PowerShell, we will get the following output.

stopped services
stopped services

We will save the script to a file by the following steps.

  • Open notepad.
  • Paste the script.
Paste the script
Paste the script
  • Save the file with a .ps1 file extension as given below.
TecKangaroo.ps1
save the file
save the file
  • Note the .ps1 file extension.

We have successfully created the PowerShell script file.

How to create a PowerShell Script file using ISE?

The ISE stands for Integrated Service Environment.  Use the following steps for launching an ISE.

  • Press the start button.

 

start menu
start menu
  • Type PowerShell.
PowerShell ISE
PowerShell ISE
  • Choose the option shown in the image.
  • You will see a small loading screen as shown here.
PowerShell ISE loading
PowerShell ISE loading
  • This is PowerShell ISE.
PowerShell ISE
PowerShell ISE
  • Enter the command as shown in the image.
get-service |? status -eq “stopped”
  • Save the file using ctrl+s.
save the PowerShell file
save the PowerShell file
  • Press f5 function key to run the script and see the output.
PowerShell ISE
PowerShell ISE

This is how we create a PowerShell file using the ISE.

How to run a PowerShell file in Windows 10?

We have learned how to create a PowerShell file in Windows NotePad.  We have also learned how to create a PowerShell file in the PowerShell ISE.  But now we will see how to run a PowerShell file.

  • Launch PowerShell.
  • Enter the following command.
Set-ExecutionPolicy RemoteSigned
set execution policy
set execution policy
  • You need to select ‘a‘ as it will allow all the scripts to run.
enter a
enter a
  • Enter the file path and the file name and press enter.
select the ps1 file
select the ps1 file
execute the script
to execute the script

This will execute the script.

What are the different permissions for executing PowerShell Script?

We can use the following command to get help regarding the set-execution policy.

get-help Set-ExecutionPolicy

It gives us the following output.

get help for execution policy
get help for execution policy

Here is a brief explanation of some of the most used policies.

  • Unrestricted – It is to run any script without any restrictions.
  • AllSigned – This policy will let only the signed scripts to run.  The scripts must be signed by a trusted publisher.
  • RemoteSigned – If a script is signed on the remote device, it will run on the remote device.  However, if the script is signed on the local device, the script must be signed using a trusted publisher.
  • Restricted – This will block all the scripts from running from a file.

Verdict:

We learned much about creating a PowerShell file.  We entered the scripts in it and saved it.  The PowerShell file must be executed after setting the appropriate execution policy.

If you want more posts on PowerShell, stay tuned to TecKangaroo.

PowerShell Files
  • Article Rating
  • Content Relevance
  • Content Clarity
  • Author Rating
4.6

Leave a Reply

Your email address will not be published. Required fields are marked *

Loading…

0

Comments

0 comments