TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Create and Run a PowerShell Script

Create and Run a PowerShell Script with What is PowerShell, History of PowerShell, Features of PowerShell, PowerShell vs CMD, PowerShell Scripting, PowerShell Versions, PowerShell Commands, PowerShell Looping, PowerShell Conditions, PowerShell Array, PowerShell Brackets etc.

<< Back to CREATE

Create and Run a PowerShell Script

Create a PowerShell script

On Windows 10, a user can create the PowerShell script using any text editor or the Integrated Scripting Environment (ISE), which is already available on every system.

Create a Script using Notepad

The following steps are used to create a PowerShell script:

1) Open Start.

2) Search for text editor such as Notepad, and click on the Notepad app.

3) Now, a new window of notepad will open. Type the script on the text file which you want to execute. For example:

Echo "Hello world....."

PowerShell While loop

4) Click on the 'File' menu in the menu bar.

5) Select the option 'save as' from the drop-down list.

6) Type the name of a file in the box and click on the 'save' button. For example: fs.ps1

7) At last, click on a save button.

Create a Script using the Integrated Scripting Environment

The following steps are used to create a PowerShell script using the ISE tool:

1) Open Start.

2) Search for the Windows PowerShell ISE, right-click on the 'Windows PowerShell ISE' and select the 'Run as Administrator' option from the drop-down list.

3) Click on the File in the menu bar.

4) Select the 'New' option to create a new empty file.

5) Write a script which you want to execute. For example:

Echo "Hello world....."

PowerShell While loop

6) Click on the 'File' menu in the menu bar.

7) Select the option 'save as' from the drop-down list.

8) Type the name of a script. And, then click on the Save button.

Enable PowerShell Scripts

When we start the PowerShell in a computer system, the default execution policy does not allow us to execute or run the scripts.

There are four different types of execution policy in PowerShell:

  • Restricted: In this policy, no script is executed.
  • RemoteSigned: In this policy, only those scripts are run, which are downloaded from the Internet, and these must be signed by the trusted publisher.
  • Unrestricted: All the scripts of Windows PowerShell are run.
  • AllSigned: Only those scripts can be run, which are signed by a trusted publisher.

Because the default execution policy of Windows PowerShell is restricted, so we cannot run any script until we change it. First, we set the execution policy to Unrestricted to execute the scripts by using the following command.

Set-ExecutionPolicy Unrestricted

Run a PowerShell script

To execute the PowerShell script from the command line, follow the given steps:

1) Type the Windows PowerShell in the start menu and then open it by clicking on a result.

2) Now, execute the script by typing the full path to the script such as (C:/desktop/fs.ps1), or if it is in current directory, type the file name followed by a backslash.


Next TopicPowerShell Comment




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf