Introduction to PowerShell
Introduction to PowerShell
Fundamentals of PowerShell
Introduction
A scripting language is a computer language that uses some instructings referred to as commands. Those commands are submitted to a computer, namely an operating system, to automatically perform some tasks. To perform such tasks, Microsoft created a scripting language named PowerShell. Actually, PowerShell is just one more version from a long line of previous scripting languages. In this series of lessons, we will learn how to use PowerShell to automate some tasks in Microsoft Windows operating systems.
Installing PowerShell
Before using PowerShell, you must have installed it in your computer. If you are using Microsoft Windows 10 or higher, it should have been installed with the operating system. If not, you download it freely from the Microsoft websites. You must then install it.
Starting PowerShell
To use PowerShell, you have many options. The primary way to use PowerShell is to launch it from the Start menu:
One way is to click PowerShell. In some cases, you will have to start PowerShell as an administrator. In that case, you would right-click PowerShell and click Run As Administrator:
After starting PowerShell, it would display like a DOS window with a command prompt:
PowerShell and Visual Studio Code
Although there are various ways you can use PowerShell from its own command prompt, Microsoft provide Visual Studio Code as a viable alternative. You can freely download it and install it on your computer. There are various ways you can use PowerShell in Visual Studio Code. As one option, like PowerShell provides a command prompt, Visual Studio Code is equipped with a terminal that you can user. As another or better option, you can create a PowerShell file in Visual Studio Code and execute it. To do that, you must install. In fact, if you create a PowerShell file and try to execute it in Visual Studio Code, you would receive a message box stating: "Do yo want to install the recommended 'PowerShell' extension from Microsoft for the PowerShell language?";
In that case, click Install. The installation would then occur:
Once that installation has been completed, you can use PowerShell in either the PowerShell prompt or in Visual Studio Code.
PowerShell and a Text Editor
One more option to use PowerShell is by using a text editor such as Notepage. To do that, you can write your code in Notepad and save it. You can then access that file from either the command prompt or Visual Studio code.
Using PowerShell
A PowerShell Line
There are various ways you can use PowerShell. The primary way to use PowerShell is to write a line or PowerShell code and execute it. To do that, after starting PowerShell, at its command prompt, type the line of code. To execute, press Enter. In the same way, you can launch Visual Studio Code. On its main menu, click Terminal and click New Terminal:
In that terminal, you can type a line of code. To execute it, press Enter.
Introduction to Values
Overview
The primary way you use PowerShell is to make it display something on the computer screen. A value is anything you display on the computer monitor. Displaying a Natural Number A natural number is one or a combination of digits. The primary way you can display such a number is to simply type the desired number on the PowerShell prompt or the PowerShell terminal (in Visual Studio Code) and press Enter. Here is an example: PS C:\Introduction> 28536
28536
Displaying a Decimal Number A decimal number is a number made of one or two section. The primary way to represent a decimal number is exactly like a natural number. A real or decimal number is different from a natural number because a decimal number can be made of two sections that each is a natural number. The sections must be separated by a special character referred to as the decimal separator. To display such a number, you can type it on the PowerShell prompt or the PowerShell terminal (in Visual Studio Code) and press Enter. Here is an example: PS C:\Windows\System32> 264.71
264.71
When a decimal number is between 0 and 1 excluded, the number can start with 0. Here is an example: PS C:\Windows\System32> 0.203749
0.203749
In that case, when representing the number, you can omit the 0. Here is an example: PS C:\Windows\System32> .203749
0.203749 |
![]() |
Displaying Characters
If you want to display something that is not a number (a character, a group of characters, or any combination of symbols), you have many options. One solution is to include the character or combination in single or double-quotes. Here are examples:
PS C:\Windows\System32> 'New Jersey' New Jersey PS C:\Windows\System32> "Bavaria" Bavaria PS C:\Windows\System32> 'Mannitoba' Mannitoba
|
|||
Home | Copyright © 2024-2025, FunctionX | Wednesday 26 February 2025, 22:31 | Next |
|