• Network
    • Basic Network
    • Linux
  • Security
  • Tips
    • Android Tips
    • Code
    • Computer Tips
    • Facebook
    • Windows 7/8/10
    • Graphics
  • Games
  • Software
    • Browsers
    • Computer Software
    • Phone Software
  • MMO
    • Advertisers – Publishers
    • Affiliate Program
    • Make money by phone
  • News
  • Knowledge
TechMody
  • Network
    • Basic Network
    • Linux
  • Security
  • Tips
    • Android Tips
    • Code
    • Computer Tips
    • Facebook
    • Windows 7/8/10
    • Graphics
  • Games
    • All
    • Action
    • Adventure
    • Casual
    • Racing
    • Simulation
    • Strategy
    10 Best Offline Games for Android in 2023

    10 Best Offline Games for Android in 2023

    Mobile Legends: Bang Bang Mod APK 1.7.44.8111 (Unlock Skin, Done View, ESP)

    Mobile Legends: Bang Bang Mod APK 1.7.44.8111 (Unlock Skin, Done View, ESP)

    PK XD Mod APK

    PK XD Mod APK 0.37.0 (Unlimited Money, Gems, Event Points)

    FRAG Pro Shooter MOD APK v1.9.1 (Unlimited Money, Joker Card, Move Speed)

    FRAG Pro Shooter MOD APK v1.9.1 (Unlimited Money, Joker Card, Move Speed)

    Among US MOD APK by TECHMODY

    Among Us MOD APK 2021.6.16 (Unlocked Skin, Always Impostor, No Kill Cooldown)

    Pixel Gun 3D Mod APK v21.3.1 (Unlimited Money, Coupons, VIP, ESP)

    Pixel Gun 3D Mod APK v21.3.1 (Unlimited Money, Coupons, VIP, ESP)

  • Software
    • Browsers
    • Computer Software
    • Phone Software
  • MMO
    • Advertisers – Publishers
    • Affiliate Program
    • Make money by phone
  • News
  • Knowledge
No Result
View All Result
  • Network
    • Basic Network
    • Linux
  • Security
  • Tips
    • Android Tips
    • Code
    • Computer Tips
    • Facebook
    • Windows 7/8/10
    • Graphics
  • Games
    • All
    • Action
    • Adventure
    • Casual
    • Racing
    • Simulation
    • Strategy
    10 Best Offline Games for Android in 2023

    10 Best Offline Games for Android in 2023

    Mobile Legends: Bang Bang Mod APK 1.7.44.8111 (Unlock Skin, Done View, ESP)

    Mobile Legends: Bang Bang Mod APK 1.7.44.8111 (Unlock Skin, Done View, ESP)

    PK XD Mod APK

    PK XD Mod APK 0.37.0 (Unlimited Money, Gems, Event Points)

    FRAG Pro Shooter MOD APK v1.9.1 (Unlimited Money, Joker Card, Move Speed)

    FRAG Pro Shooter MOD APK v1.9.1 (Unlimited Money, Joker Card, Move Speed)

    Among US MOD APK by TECHMODY

    Among Us MOD APK 2021.6.16 (Unlocked Skin, Always Impostor, No Kill Cooldown)

    Pixel Gun 3D Mod APK v21.3.1 (Unlimited Money, Coupons, VIP, ESP)

    Pixel Gun 3D Mod APK v21.3.1 (Unlimited Money, Coupons, VIP, ESP)

  • Software
    • Browsers
    • Computer Software
    • Phone Software
  • MMO
    • Advertisers – Publishers
    • Affiliate Program
    • Make money by phone
  • News
  • Knowledge
No Result
View All Result
TechMody
No Result
View All Result

Instructions for programming PowerShell on Windows

TechMody by TechMody
March 4, 2021
in Code

Table of Contents

  1. How to create a PowerShell script on Windows 10
    1. Create scripts using Visual Studio Code
    2. Install Visual Studio Code
    3. Install the PowerShell extension
    4. Create PowerShell script on Visual Studio Code
    5. Create PowerShell Script in Notepad
    6. Script creation using the Integrated Scripting Environment
  2. How to run a PowerShell script on Windows 10
  3. Download PowerShell textbooks and exercises

Imagine, your company is newly established, you are an IT Manager, your task is to create 1000 Windows users for 1000 employees. If you are a regular user, you will go to Control Panel, click on User and create an account? Is not! If it is the IT Manager, they will write scripts on Powershell to automate User creation.

On Windows, PowerShell is a command-line tool designed by Microsoft to run commands and scripts to change system settings and automate tasks. It is similar to Command Prompt, since Microsoft originally created PowerShell to replace Command Prompt. However, PowerShell has more capabilities than a command-line interface (CLI) such as providing an extensive toolkit, and has more flexible control capabilities. Also, unlike Command Prompt, PowerShell is available on Windows, macOS, and Linux.

Instructions for programming PowerShell on Windows 16

A script is just a set of lines of code saved to a text file (using the file extension “.ps1”) that PowerShell can understand and execute to perform various actions.

A little bit confusing is that the default security protocol always blocks any scripts from running on the device. This means that when double clicking on the file “.ps1” on Windows 10 nothing will happen and if you try to run the script in PowerShell, you will see the error “cannot be loaded because running scripts is disabled on this system” . However, it is not impossible to run the script on your computer. You just need to enable a correct executable number,

So, in this article, I will guide you through the steps to successfully write and run your first script on PowerShell using Visual Studio Code, Notepad and the PowerShell Integrated Scripting Environment (ISE) control panel.

How to create a PowerShell script on Windows 10

On Windows 10, you can create a PowerShell script file using virtually any text editor or ISE console. However, I recommend using Visual Studio Code (my hobby :v) to write scripts and use the PowerShell extension.

Create scripts using Visual Studio Code

Visual Studio Code – also known as VS Code – is a free cross-platform code editor and can use extensions that provide an environment for writing virtually all programming languages. And when you add the PowerShell extension, you get a completely different scripting experience, even with the help of IntelliSense (self-completion of code).

The new experience doesn’t mean it will be default, but the PowerShell ISE won’t disappear either. However, ISE will not add new features and will not support PowerShell versions 7 and above.

Install Visual Studio Code

To install Visual Studio Code on Windows 10, you need to follow these steps:

1. Go to the Download page of Visual Studio.

2. Click the Windows button to load the installer.

Instructions for programming PowerShell on Windows 17

3. Double click on the downloaded file to start installing VS Code.

4. Agree to the terms of the agreement.

5. Click Next.

Instructions for programming PowerShell on Windows 18

6. Continue to click Next.

7. Click Next again.

8. Select some additional necessary additional options (it’s your own choice).

Instructions for programming PowerShell on Windows 19

9. Click Next.

10. Click the Install button.

11. Finally click Finish.

After completing the steps above, you need to continue to install the PowerShell extension.

Install the PowerShell extension

To install the PowerShell extension on VS Code, you need to do the following:

1. Open VS Code.

2. Click the Extension tab on the left panel.

3. Search for PowerShell and select the first result.

4. Click the Install button.

Instructions for programming PowerShell on Windows 20

So you can start writing Script already.

Create PowerShell script on Visual Studio Code

1. Open VS Code.

2. Click File on the menu and select New File.

Instructions for programming PowerShell on Windows 21

3. Select File and click Save as.

Instructions for programming PowerShell on Windows 22

4. In the “File name” section you must name the file with the extension .ps1, for example: first_script.ps1.

5. Click the Save button.

6. Paste the following command into your script and run:
Write-Host "Congratulations! Your first script executed successfully"

The above command will output the phrase “Congratulations! Your first script executed successfully ”on the screen.

7. Press the Run button on the top right or press F5 to run the script.

Instructions for programming PowerShell on Windows 23

8. Click File on the menu.

9. Click Save.

Create PowerShell Script in Notepad

1. Press Start Menu.

2. Search for Notepad and select the first result.

3. Paste the following command into Notepad:

Write-Host "Congratulations! Your first script executed successfully"

Instructions for programming PowerShell on Windows 24

4. Click File.

5. Select Save as.

6. Write the filename with the .ps1 extension, for example: first_script.ps1.

Instructions for programming PowerShell on Windows 25

7. Finally click Save.

Script creation using the Integrated Scripting Environment

Alternatively, you can use the built-in PowerShell ISE control panel to write scripts on Windows 10.

The Integrated Scripting Environment is an advanced PowerShell development tool, but you can get started with these steps:

1. Press Start Menu.

2. Search Windows PowerShell ISE, right-click the first result and select Run as administrator.

3. Click File.

4. Select New to create the .ps1 file.

Instructions for programming PowerShell on Windows 26

5. Paste the code below into:

Write-Host "Congratulations! Your first script executed successfully"

Instructions for programming PowerShell on Windows 27

6. Click File.

7. Select Save.

8. Enter the script name, for example: first_script.ps1.

Instructions for programming PowerShell on Windows 28

9. Select where to save the script.

10. Finally click Save.

After you complete the above steps using Notepad, Visual Studio Code, or PowerShell ISE, the script is ready to run, but it will crash by default. This is because PowerShell is installed by default to always block the execution of any scripts. (The only exception is if you run the script in Visual Studio Code or PowerShell ISE.)

How to run a PowerShell script on Windows 10

If you want to run scripts using PowerShell, you have to change the execution policies on Windows 10.

To change the execution and run policy for PowerShell scripts, you need to do the following:

1. Press Start Menu.

2. Search for PowerShell, right-click the first result, and select Run as administrator.

3. Paste the command below into PowerShell and press Enter:

Set-ExecutionPolicy RemoteSigned

4. Type A and press Enter (if required by PowerShell).

Instructions for programming PowerShell on Windows 29

5. Type the following command to run the script and press Enter:

& "C:\PATH\TO\SCRIPT\first_script.ps1"

In the above command, make sure to change “PATH\TO\SCRIPT” to the location of the script on your machine.

For example, this command runs mscript stored in the Download folder:

& "C:\Users\username\Downloads\first_script.ps1"

Instructions for programming PowerShell on Windows 30

After you have completed the above steps, you should be able to run the script.

On Windows 10, PowerShell includes four execution policies:

  • Restricted – Stop running any scripts.
  • RemoteSigned – Allows scripts to be created on the device, but scripts created on other computers won’t run unless they are signed by trusted developers.
  • AllSigned – All scripts will be run, but only scripts with a trusted signature from their developer.
  • Unrestricted – Run any script without any restrictions.

In the above article, I used the command to allow local scripts to run on Windows 10. However, if you don’t plan to run this script often, you can restore default setting to block the scripts. Unreliable command using the Set-ExecutionPolicy Restricted command.

Download PowerShell textbooks and exercises

TechMody has compiled 2 of the most complete Ebooks about PowerShell for you to self-study. The content of the ebook is easy to understand, with more than 100 exercises for you to practice on your own. If you are a network administrator or you are going deeper into PowerShell programming, then you should check out this ebook

Download Ebook and PowerShell exercises

The content includes:

  1. PowerShell Notes for Professionals book
  2. Windows Powershell 3.0 Step by Step
  3. 100 Powershell exercises and mockups
Previous Post

Free download Visual Studio Code software for web developers

Next Post

8 Best Linux OS You Should Try in 2021

TechMody

TechMody

Knowledge is like a fire, the more you share it, the more it will burn!

Related Posts

No Content Available
Next Post
8 Best Linux OS You Should Try in 2021

8 Best Linux OS You Should Try in 2021

Recenter Post

10 Best Offline Games for Android in 2023

10 Best Offline Games for Android in 2023

January 11, 2023
Mobile Legends: Bang Bang Mod APK 1.7.44.8111 (Unlock Skin, Done View, ESP)

Mobile Legends: Bang Bang Mod APK 1.7.44.8111 (Unlock Skin, Done View, ESP)

February 7, 2024
How to increase Laptop Battery Life 2023

How to increase Laptop Battery Life 2023

January 10, 2023
How to Learn and Get 100% Free Google Data Analytics Professional Certificate

How to Learn and Get 100% Free Google Data Analytics Professional Certificate

January 9, 2023
PK XD Mod APK

PK XD Mod APK 0.37.0 (Unlimited Money, Gems, Event Points)

February 7, 2024

TechMody

A place to share knowledge you've never learned in school!

We are ready to welcome your comments, as well as articles sent to TechMody.

Join TechMody to build the biggest IT community!

Introduce

TechMody is a website that freely shares all information technology knowledge. TechMody provides all solutions for network computers, software, graphics and MMO.

Contact

Email: samtn.ktc[@]gmail.com

Recent Posts

  • 10 Best Offline Games for Android in 2023
  • Mobile Legends: Bang Bang Mod APK 1.7.44.8111 (Unlock Skin, Done View, ESP)
  • How to increase Laptop Battery Life 2023
  • How to Learn and Get 100% Free Google Data Analytics Professional Certificate
  • PK XD Mod APK 0.37.0 (Unlimited Money, Gems, Event Points)
  • About
  • Advertise
  • Privacy & Policy
  • Contact

© 2024 TechMody - We bring you useful knowledge about Technology.

No Result
View All Result
  • Network
    • Basic Network
    • Linux
  • Security
  • Tips
    • Android Tips
    • Code
    • Computer Tips
    • Facebook
    • Windows 7/8/10
    • Graphics
  • Games
  • Software
    • Browsers
    • Computer Software
    • Phone Software
  • MMO
    • Advertisers – Publishers
    • Affiliate Program
    • Make money by phone
  • News
  • Knowledge

© 2024 TechMody - We bring you useful knowledge about Technology.