👨‍💻 Windows Powershell: What is That and How to Use It? Main Commands 🖥️⚙️

Feb 18, 2020 11:00 · 1347 words · 7 minute read windows family pressing command dir

Hello everybody! In today’s video, we will discuss Windows PowerShell to find out what is that, why we need it, what are its main functions and commands, and we will also explore writing and running some simple scripts. You can find PowerShell by right-clicking on the Start button, and there are two options to start it. Windows PowerShell was first introduced as an integrated component of Windows 7. Besides, the second option (run PowerShell as administrator) was available for earlier versions of the operating system, such as Windows XP, Windows Vista, and Windows Server since 2003. Most likely, this tool will be of little value for ordinary users, but it can be very helpful for system administrators.

00:50 - We created this video for beginners to cover basic stuff to know about PowerShell, so power users may not learn anything new today. So, let’s begin. What is PowerShell and why we need it Let’s start by answering two essential questions: what is this tool and why you need it. PowerShell is a modernized and standardized version of the command prompt that provides access to a more flexible way to manage your computer and its settings. In fact, it’s the same good old command prompt but with more functionality to give IT professionals more opportunities to configure operating systems of the Windows family. In other words, it’s a versatile administrative tool.

02:04 - This shell gives you convenient access to such controls as COM, WMI and ADSI, and lets you run ordinary command prompt commands to create a unified environment where administrators can perform various tasks on local and remote systems. PowerShell functionality and main commands The functionality of this tool is impressive: It can manage services, accounts, file storage devices, processes and even servers. You can work with COM, NET and XML objects, run external commands, create and perform your own scenarios, and do a number of other things. Power Shell has its own set of commands, just like CMD console, which are known as commandlets. The syntax, commandlet definitions and their settings differ from their standard counterparts, but this tool can recognize many CMD commands as well.

02:56 - Power Shell understands commands like cd, dir, copy and others; for PowerShell, they are pseudonyms or aliases which are used for convenience. For example, the command dir, used to view the file system corresponds to the commandlet Get-ChildItem. PowerShell provides both an entirely console-type interface and a full-featured development environment PowerShell ISE (Integrated Scripting Environment) used to write scripts. To open the command line interface, just type “powershell” in the Run window; you can open this window by pressing the key shortcut Win + R. As to PowerShell ISE, you can start it by typing its name in the Run window.

03:45 - ISE gives developers more opportunities with things like syntax coloring, tab completion and other features. A dedicated column lists all possible commands, their description and the search feature. Main commands To get acquainted with PowerShell, run the command Help. You will see a brief description and examples of using this tool. Use the command Get-Command to display all available commands.

04:25 - In PowerShell ISE, all commands are listed on the right and arranged by alphabet and modules, and you can search the one you need by name, if necessary. When you take a closer look at the information shown after running Get-Command, you will notice that Windows PowerShell contains aliases, functions and commandlets. Aliases are meant to simplify the process of entering commands (for example, clc is the alias for the command Clear-Content). Commandlets (cmdlet) are lightweight versions of all commands integrated with Windows PowerShell. Here are some main PowerShell commands. Cd - navigation through folders. The difference between this commandlet and its standard command prompt version is that the commandlet can also navigate the registry.

05:15 - For example, to go to the registry branch HKEY_LOCAL_MACHINESOFTWARE you should type the following: cd hklm:software The command Get-Alias displays the list of all aliases in Power- Shell. The pseudonym for this command is gal. To list all pseudonyms with their prototypes, enter the following command: gal | select name, definition The Get-Command is used to display the list of available commands, and after running Help Get-Command you will see a compete description of the command Get-Command, including its purpose, syntax, options etc. Using another command, Get-Service, you will see the list of all services running on this computer. To view the list of processes running at the moment, type the command Get-Process. The command Set-Content (or its pseudonym sc) is used to write values into a file.

06:32 - If the designated target file doesn’t exist, this command will create it. The example below illustrates how the value “My data” is written into a file named newfile.txt: sc mynewfile.txt -value “My data” The opposite of sc is the command Get-Content (gc). The command gc is used to read contents of a file. For example, the command shown below helps you display the contents of the file newfile.txt: gc mynewfile. txt The command Get-Eventlog lets you extract Windows event logs. Just like with Get-Process, there is no need to use any additional tools. The example below illustrates extracting 10 latest entries from the event log: get-eventlog -newest 10 -logname system Also, Windows PowerShell supports autocompletion for anything you type. To see this feature at work, type Get-P and press the TAB button: you will be able to choose from all commands that begin with these symbols. To receive information on on process only, add its name after Get- Process. Get-Process and the process name.

07:49 - Get-Process explorer The tool contains an impressive list of hundreds of commands. Memorizing all their names and properties is impossible, but it’s also unnecessary: most of them are used vary seldom, and some are not used at all. Pay attention only to the most important and practical ones, that is, the ones which are most useful. Write and run simple scripts Additionally, you can create your own batch files looking like files with the extension *.ps1 and containing PowerShell commands, and run them.

08:20 - In spite of PowerShell being an integrated element of the Windows operating system, you can’t run its scripts by just double-clicking on them. You need to right-click on the script and select “Run with PowerShell.” To observe security requirements, batch files have to be signed. You can check current settings for this policy by entering the command Get-ExecutionPolicy. As a result, you will see one of the five possible values: Restricted — you can’t run scripts (It’s a standard setting); AllSigned — you can run scripts signed by a trusted developer; before running a script, PowerShell will ask you for confirmation; RemoteSigned — you can run your own scripts or those signed by a trusted developer; Unrestricted — you can run any scripts.

09:14 - For testing, you can disable the setting to run only signed files: Set-ExecutionPolicy Unrestricted Mow you can run any scripts you like. Scripts to edit the registry, create or remove directories and files, modify system settings and so on. A script is basically a set of commands to automate a task which would have to be performed manually otherwise, with the help of the program’s interface. For example, the following script writes text to a file: “Hello!” | Out-File C:\test.txt After your PowerShell testing period is over, don’t forget to enable the setting to run only signed files again.

10:00 - Type the following command: Set-ExecutionPolicy AllSigned Windows PowerShell can’t be seen as a simple and user-friendly tool, on the contrary, it’s quite difficult to understand, and there is no way to master it in a day or two. Anyway, I hope that this video gave you a certain idea what PowerShell tool is. That is all for now! Hopefully, this video was useful. Remember to click the Like button and subscribe to our channel. Hit the bell button to receive notifications and never miss new videos. Leave comments to ask questions. Thank you for watching. Good luck. .