PowerShell cmdlets. What is Windows PowerShell and what is it needed for what

November 5, 2014 at 20:07

Jump Start in PowerShell (Part I)

  • System administration ,
  • PowerShell
  • Tutorial

Only automation. Only PowerShell.

Preface

As a hobby and in the presence of time, I teach students to Ukit (former Moscow State College information technologies). On the this moment I have little time to give it a group of students, but it is enough to prepare a post here on Habré.

I work as a system administrator in a large not IT company with a big string for IT resources. By the nature of the activity it seems to decide a large number of User service tasks.

With the PowerShell language, I got acquainted about two years ago, but it took him closely only a year later, not realizing the initial opportunities at first. In the article, first of all, I will focus on those who want to start working with PowerShell, but until he trusts him or does not know how to approach this miracle.

Attention: PowerShell is addictive.

Introduction

Wikipedia tells us:
Windows PowerShell - an extensible means of automation from Microsoft.Consisting of a shell with a command line interface and related scripts.

PowerShell looks like a command line:


powerShell.exe.

Or in the form of an application:


powerShell_ise.exe.

PowerShell_ise.exe. Called an integrated scenario environment - Windows PowerShell ISE. Allows you to work with a language in a convenient syntax highlighted environment, command constructor, autofill commands by pressing TAB and other charms. Ideal for creating and testing scripts.

For launching environment powerShell.exe. or powerShell_ise.exe. It is enough to dial a similar name in the row.

PowerShell script file has an extension .ps1.

The script will not be able to run double LKM. This is done specifically in order not to harm the system randomly running script.

To start, by clicking PCM, select "Run using PowerShell":

In addition to the fact that there is a limit on the launch of scripting of the LKM, by default, the execution of scenarios in the system is prohibited, again, according to the reason described above - do not harm the system. To verify the current execution policy, we will execute the command:

Get-ExecutionPolicy

We get one of the following values. With great probability if it was the first launch, we get Restricted.

  • Restricted - scripts cannot be launched;
  • AllSigned. - Only scenarios signed by the trusted publisher can be launched. Before performing the scenario of the trusted publisher will be requested confirmation;
  • Remotesigned. - allowed to perform the scripts and downloaded scenarios signed by the trusted publisher;
  • Unrestricted - No restrictions, all scripts can be launched.

To fulfill and testing the policies to Remotesigned. By commanding:

Set-ExecutionPolicy Remotesigned

Getting to work

CMLL
  • Commands are called PowerShell commands, in which various functionality is laid;
  • Cups can be both system and custom created by anyone;
  • Clasles are referred to the Glagol-noun rule, which simplifies their memorization;
  • Coldcles output results in the form of objects or their collections;
  • Cmdlets can both receive data for processing and transmit data on the pipeline (about conveyors later);
  • Cups are not sensitive to the register (you can write and get-process, and get-process, and get-process);
  • After cmdlets, it is not necessary to put " ; ", except when we perform several cmdlets in one line (get-process; Get-Services).

For example, to get current processes, we will execute the command:

And we get the result:

Try to perform yourself:

Get-Service # to obtain the status of services running on computers

Get-Content C: \\ Windows \\ System32 \\ Drivers \\ ETC \\ HOSTS # to get the contents of the file. IN this case, Hosts file

It is not necessary to know all the cmdlets. Get-Help. Save the situation.
Information about all available cmdles can be obtained by entering the following command:

Get-Help -Category Cmdlet

If we use PowerShell ISE, we facilitate the development process.
Just enter a dash sign " - "After the clarket was introduced, and we will get everything possible options Parameters and their types:

Try to execute:

Get-service -name p *

If, nevertheless, we will forget what properties there is from one or another cmdle, we ride it through Get-Member.:

Get-Process | Get-Member # sign "|" called conveyor. About him below.

Not enough information? Turn to the help with the parameter -Examples.:

Get-Help Get-Process -Examples

We get a description Get-Process.Yes, and with examples of use:

  • Clasles may have abbreviated names - aliases. For example, instead Get-Help. You can use simple Help.. For all reductions, perform Get-Alias..

Try to execute:

START-PROCESS NOTEPAD

What is similar to recording:

Start Notepad.

And now stop the process:

STOP-PROCESS -NAME NOTEPAD

SPPS -Name Notepad.

Slightly earlier we said that clocles are called the Glagol-noun rule. Clarify that the verb does not have to be Get.. Besides what we can get, we can ask SET. (Remember, Set-ExecutionPolicy), launch Start.stopping Stop., output Out.Create New and many others. The name of the cmdlet is not limited to anything and when we will create our own with you, we can call it as your heart.

Let's try to execute the file:

"Hello, Hub!" | Out-File C: \\ Test.txt & C: \\ Test.txt

By the way, it can be written in the same way as:

"Hello, Hub!" \u003e C: \\ Test.txt & C: \\ Test.txt

With mysterious letters and persistently flashing cursor? This is a command line. The utility is present in all windows versions. With it, it is convenient to manage the system, call programs, find files. But for professional work CMD is not functional enough. Therefore, Microsoft decided to fix all console minuses and released the product under by the name of Windows PowerShell. What is it and how to use development, read on.

What is PowerShell from Windows

PowerShell is an interactive object-oriented command environment with script language functions. The official release of PowerShell 1.0 from Microsoft took place on November 14, 2006. The developers combined the interface of the usual CLI command line with a platform for managing local and remote networks .NET Framework.

Note that Windows PowerShell is not a simple operating shell. Microsoft managed to create a powerful, expandable and at the same time a flexible control tool, which is capable of functioning as a selected scenario language.

On August 18, 2016, Microsoft announced that Windows PowerShell is now an open source product available to each developer. Also, the company added support for UNIX-oriented operating systems, including Linux and OS X distributions.

How to manage PowerShell

Cmdlets are used to run tasks, or cmdlets. These are small commands recorded in the form of executable files. In version 2.0 PowerShell for Windows XP and Server 2008 R2, the creators have added modules that allow you to manage large quantity Resources, including Active Directory and Exchange Server.

Now in the PowerShell automation tool, over 130 modules and commands are embedded. They provide access to files, networks, registry, administration and other system features:

  • setting time and dates;
  • work with folders and separate files;
  • obtaining assistance and additional information;
  • import and data storage;
  • methods for creating scripts;
  • individual scripts and applications;
  • check security system and work with descriptors;
  • system administration;
  • check disk space.

Considering that Windows PowerShell is an expandable environment, users can create their own teams, write "author" modules using a language .Net.

Getting started with PowerShell

In 2016, the last beta version 6.0 PowerShell was released. In Windows 7, 8 and 10, the utility is built-in. If you use another operating system, the application will have to download. To do this, go to the official site of Microfoft.com and in the search window, enter Installing Windows PowerShell. The system will automatically translate to the page with the latest product releases. Select your OS from the list and click Download.

When the file is fully loaded, open it with a double mouse click. By default, the environment will be installed in ProgramFiles \\ PowerShell \\ and create a shortcut in the Start menu. If you are a happy Windows user, click on the system icon in the lower left corner and enter PowerShell to "find programs and files". Run the application, enter your first cmdlet and start working.

List of necessary commands and instructions for PowerShell

The name of each cmdlet is represented in the form "verb-noun" or "Action-Object". We offer a list of the most important CMDLETS PowerShell for Windows 10 and previous versionsstarting with XP. They will be useful even to novice users who have just learned how to maintain text documents.

  1. Get-Help. Built in the core cage celler. Designed to call a certificate and provides useful information On syntax, programs, their appointment, other celts. If in the usual command interpreter you wrote IPCONFIG /?, Then in PowerShell you need to dial GET-HELP Get-Process.
  2. Get-Content. Simplifies the procedure for reading files for beginners and system administrators. If earlier it was necessary to open the handle and read all the lines of the document, now just give the file cmdlet. To do this, write in the C: \\\u003e GET-CONTENT C: \\ ... \\ "file name" in the console. "Extension".
  3. Get-service. Access to information about the services installed on the computer.
  4. Get-Member. Gives information about the returned cmdlet object, allows you to see its properties and methods.
  5. Get-Command. Searches for cmdlets, returns all information about them, including data on functions, scripts, applications, and other elements. In version 5.0 PowerShell for Windows 10 in Get-Command, the Version column has been added, and now the commanders displays several versions of the same module at once.
  6. STOP- \\ START-SERVICE. An indispensable assistant for administrators. The cmdlet launches and stops services on deleted and local computers.

Special Symbols for Scripts

In addition to cmdlets, the PowerShell utility in Windows 7 and above includes special characters, such as $ _ or (). The greatest perplexity of the icons cause newcomers who did not have the case with Linux-like systems or programming.

  1. Vertical trait "|". This symbol is used for programs with conveyor data transfer. When working with the console, it includes when they want to specify the command to the right of the vertical feature to accept the output from the left command. In PowerShell, the vertical feature is used by almost the same purpose, combining several teams at once. For example, create a new username, add it to a group and reset the default password.
  2. Function sign "()". Allows you to effectively monitor the process of execution of scenarios. As in C-like programming languages, the PowerShell function is formed by entering into several cmdlets in curly brackets and is ready to start the required number of times.
  3. Special symbol $ _. Used to write scripting blocks, filters and procedural expressions. $ _ takes the value of the current object and transmits it to the following. Using the dollar sign, without a lower underscore, you can designate or enter a variable: $ var \u003d "Hello".

What is PowerShell ISE

Included with the PowerShell utility is a graphic windows application PowerShell ISE. This is a shell, or an integrated environment for writing scripts. ISE provides developers a huge range of possibilities. With it, you can create, debug and edit scripts, open text and XML files. Color highlighting of the syntax greatly facilitates testing and search for errors in the code.

ISE is much more convenient than the PowerShell console and can completely replace it. Using the environment, you can copy and insert large code fragments, start not all script, but its separate parts. Unlike PowerShell, the window size in the ISE is easily changing the mouse pointer, as when working with the usual program.

To try the ISE environment, enter PowerShell ISE in the Start menu. If you are not using Windows, but another OS, download and install a distribution from the official site. After starting the application, a window of three parts will open. The top scripts are written at the bottom - PowerShell teams, and in the middle there is a result.

Start acquaintance with ISE and in the lower window, enter Get-Process. Press TAB several times. Next to the cmdlet will appear its parameters that will change after each keystroke. This will be your first session with a script environment from Microsoft.

Equally, however, it allows you to perform the usual command line commands to create a single environment in which administrators could perform various tasks on local and remote systems.

These administrative tasks are usually performed using cmdlets (in the original cmdlets.), which are specialized .NET classes. The user can combine them in scripts (scenarios) using various designs, command line utilities and referring to normal classes .NET, WMI or COM objects. In addition, you can use various data warehouses, such as the Windows file system or registry, which are provided by PowerShell through suppliers (English. providers).

Windows PowerShell also provides an embedding mechanism, thanks to which the PowerShell executable components can be built into other applications. These applications can then use PowerShell functionality to implement various operations, including provided through graphic interface. This approach is applied to Microsoft Exchange Server 2007 to implement the control functionality in the form of PowerShell cmdles and graphic control utilities in the form of PowerShell shells that cause the necessary cmdlets. Thus, the graphical control interface is over the intermediate layer - PowerShell. Others microsoft applications, Including Microsoft SQL Server 2008, System Center Operations Manager and System Center Data Protection Manager also provide access to their management interfaces through the PowerShell cmdlets. In the future, all Microsoft server applications on windows platform will use PowerShell in one way or another.

Windows PowerShell includes its own extensible help, available (including from the command line) via the Get-Help cmdlet.

Prehistory.

Clelyt

Scenarios

PowerShell includes a scenario language with dynamic types, on which you can implement complex operations using cmdlets. Script language supports variables, functions, branch designs (IF-THEN-ELSE) cycles (while, do, for and foreach), structured error processing and many other features, including the integration of C.NET. Variables in PowerShell are denoted by $ prefix before the name; They can be assigned any meaning, including the withdrawal of cmdlets. Although the language itself is not strictly typed, inside the variables are saved with their types that can be basic types (eng. primitive Types.) or objects. Rows can be enclosed in single quotes or dual quotes: When using double quotes, the variables contained in the string will be replaced with their values. In accordance with the syntax of the variables, if the path to the file is placed in curly brackets with a preceding dollar sign (that is, $ (C: \\ Foo.txt)), then this will be a link to the contents of the file. All that will be assigned to such a variable will be recorded in the file, and on the contrary, the contents of the file will be issued when accessing its contents.

You can handle the properties and methods of the object using the point (.), As in the syntax. PowerShell provides special variables such as $ Args, containing an array of all unnamed command line arguments, transmitted functions, or $ _, referring to the current object in the conveyor and other structures. PowerShell also contain arrays and associative arrays. In addition, PowerShell automatically calculates arithmetic expressions entered on the command line, and understands popular abrigament, such as GB (GB), MB (MB) and KB (CB).

In PowerShell, you can create your own functions that accept the parameters using the function of the FUNCTION. The popular problem for many beginners is that the functions accept arguments separated by not commas, but spaces (like command line utilities or cmdlets):

  1. : Causes a function with two arguments.

These arguments can be tied to the parameters specified in the declaration of the function. Also, they can also contact them through an array of $ args.

  1. (, ): Causes a function with one argument, which is an array of two elements.

PowerShell allows you to call any .NET methods by concluding their space names in square brackets (), and then using a couple of colors (: :) to indicate the static method. For example :: Writeline ("PowerShell"). Objects are created using the New-Object cmdlet, add new properties to them using the Add-Member cmdlet.

For PowerShell error handling provides a mechanism based on on-line. In case of error, objects are issued containing error information (Exception object) that are intercepted keyword Trap. However, behavior when errors occur configured. So, you can configure PowerShell so that in case of an error, it silently continued to execute without intercepting the error. The second version of PowerShell also added the Try Catch Finally design.

Scenarios written in PowerShell can be saved between sessions in files.ps1. Then you can use the entire script or individual functions from it. Scripts and functions are used like cmdtam, that is, they can be commands in the conveyor, they can transmit parameters. Objects can be transmitted between scenarios, functions and cmdlets in the conveyor. However, the execution of PowerShell scripts is prohibited by default, and it must be enabled using the Set-ExecutionPolicy cmdlet. PowerShell scripts can be signed by a digital signature to verify their integrity.

PowerShell 2.0

Microsoft has released PowerShell 2.0 as part of Windows 7 and Windows Server 2008 R2. Windows PowerShell 2.0 is preset in these systems. Exception is the mode windows installations Server 2008 R2 in Core mode, where PowerShell 2.0 can be configured manually. For older platforms, it is available as part of Windows Management Framework. PowerShell 2.0 makes some changes to the scripting language and API for embedding, in addition to the new 240 cmdth.

Incomplete list of new features included in PowerShell 2.0:

  • PowerShell Remoting. Using WS-Management, PowerShell 2.0 allows you to call scripts and cmdlets on remote machines (including several simultaneously), monitor the status of their execution and get results in the form of objects (through serialization - deterialization). It is also possible to establish interactive sessions and sessions with limited functionality.
  • Background work. Ability to call the sequence of commands asynchronously. Works can be run on a local machine or several remote machines. Works can not use interactive cmdlets.
  • Transactions. Allow the developers of cmdlets and suppliers to implement transactional operations. PowerShell 2.0 includes cmdlets for initialization, confirmation and rollback of transactions and the ability to manage transactions and use them in cmdt and suppliers.
  • Advanced Functions. The ability to develop full-fledged cmdlets using only PowerShell itself.
  • Steppablepipelines. Allows the user to monitor the BeginProcessing (), ProcessRecord () and EndProcessing () functions when calling a cmdlet.
  • Modules. Allow the authors of scenarios and administrators to organize PowerShell scripts and place them in self-sufficient modules. The code from the module is performed in its own, independent context and does not affect the environment outside the module. Using the script, modules can declare a limited environment. Modules may contain public and private functions and variables.
  • Data language. A subset of the PowerShell language that allows you to separate data definitions from executable scenarios code and makes it possible to import localized strings to the script during execution.
  • Debugging scripts. Ability to install interrupt points (eng. breakpoints.) In PowerShell scripts or functions. Interrupt points can be installed on strings, columns, commands, or read operations and / or recording variables. There are cmdlets for installation and control of interruption points in scenarios.
  • Eventing. This feature allows you to listen, redirect, and perform actions when the management or system events occurs. Thanks to the event, the PowerShell host can be notified of changes in the status of managed objects. Also allows scenarios to subscribe to ObjectEvents, Psevents and WMIEVENTS and process them synchronously and asynchronously.
  • Windows PowerShell Integrated Scripting Environment (ISE). PowerShell 2.0 includes a graphical shell for a language in which the built-in debugger is included, the syntax backlight, the automatization of commands. The shell allows you to run several independent PowerShell consoles with full Support of Unicode in the interface with bookmarks. Thanks to the support of remote execution, some consoles can be performed on other computers. In addition, ISE allows you to perform allocated part of the scenarios, contains a built-in editor and allows you to expand and complement your interface using PowerShell.
  • BITS TRANSFER - built-in support for the transfer of files over a network with prioritization, multithreading, resumption and asynchronous work based on the Background Intelligent Transfer Service technology.
  • Many new cmdlets, including, for example, Out-GridView, which makes it possible to display the results of the conveyor in a graphical table (based on WPF), with sorting and instant search capabilities.
  • New Operators -Split, -Join and substitution operator (@).
  • Processing errors with try-catch-finally. Unlike other .Net languages, in PowerShell you can specify several types of exceptions for one Catch block.
  • Block comments. PowerShell 2.0 supports block comments (plus to already existing line-up #) using<# и #> as limiters.
  • New APIs added different capabilities, from greater control over PowerShell parser to the ability to create limited sessions (English. restricted Runspace.) In which you can perform only a limited set of instructions and PowerShell commands.

Comparison of cmdlets with similar teams

The following table contains a sample of cmdlets supplied with PowerShell, with the maximum similar commands from other widely known command line shells.

It should be noted that this table is given for superficial familiarization, it does not cover all the features of the shells represented.

Windows PowerShell.
(Cmdlet)
Windows PowerShell.
(Alias)
cmd.exe / Command.com.
(MS-DOS, Windows, OS / 2, ETC.)
Bash
(UNIX, BSD, Linux, Mac OS X, etc.)
Description
Get-location gL, pwd. pwd. Displays the current working directory
Set-location sL, CD, CHDIR , CHDIR Changes the current catalog
Clear-Host. cLS, Clear cLS. clear Clears the screen
Copy-Item. cPI, Copy, CP copy. Copies one or more files or directories (in PowerShell you can also copy objects of other data providers)
Get-Help. help, Man. help. man. Help by teams
Remove-Item. ri, Del, Erase, Rmdir, RD, RM del, Erase, Rmdir, , rmdir Deletes the file / directory (or other item in PowerShell data providers).
Rename-Item. rNI, REN. ren, Rename. Rename file / directory
Move-Item. mI, MOVE, MV move. Moves the file / directory to a new location
Get-Childem. gCI, DIR, LS dir. Displays all files / directories in the current directory
Write-Output echo, Write. echo. echo. Displays strings, variables for standard output
Pop-location popd. popd. popd. Changes the current directory to the one that was last placed in the stack
Push-location pushd. pushd. pushd. Places the current directory on the stack
Set-Variable. sV, SET. sET. sET. Setting the value of the variable / creation of the variable
Get-Content gC, Type, Cat type cat. Gets the contents of the file
SELECT-STRING. find, Findstr. grep. Displays strings suitable under the condition
Get-Process. gPS, PS. tLIST, TASKLIST. Displays all running processes
Stop-Process. sPPS, KILL kill, Taskkill. kill Stops a running process
Tee-Object. tee. n / A. tee. Sends input data to a file or variable, then transmits them further by conveyor

see also

  • PowerShell ISE

Notes

Literature

  • Popov A.V. Introduction to Windows PowerShell. - St. Petersburg. : BHV-Petersburg, 2009. - P. 464. - ISBN 978-5-9775-0283-2

Links

  • Windows PowerShell 1.0 installation package download center for Windows Vista
  • Report on PowerShell Opportunities and Script Writing Fundamentals
  • Windows Management Framework (including PowerShell 2.0, WinRM 2.0 and BITS 4.0) for Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008
  • Blog "PowerShell and other scripts" (rus.)
  • (rus.)
  • "PowerShell Blog and Not Only" (Rus.)
  • FREE RUSSIAN BOOK O POWERSHELL (RUS.)
  • Second Free English Book About PowerShell (English)
  • Windows PowerShell Web Node (English)
  • PowerShell Captain and Administration of the Future (RUS.)

Windows PowerShell is one of the important tools in the system of system windows administrator. PowerShell is a powerful tool that should not be neglected. This article aims to provide basic work skills with Windows PowerShell.

PowerShell is something more than just a command line shell. The first version of PowerShell appeared in 2006, the reason for its development was the primitiveness of the classic team windows stringsnot allowed to perform complex algorithms.

Windows PowerShell is preset in Windows 7, 8, 8.1 and Windows Server 2008 R2, 2012 R2 systems, and can also be added to Windows XP SP3, Vista and Windows Server 2003 SP2. The PowerShell interface resembles a well-known command line interface.


Windows interface PowerShell

As mentioned above, the command line interface is not limited. PowerShell provides the system administrator's own scenario language, which allows you to automate complex actions.

The commands running in PowerShell can be in the form of cmdlets, functions, scripts and external executable files.

Clelyt - This is a new type of commands built into PowerShell. The commands of this type are compiled in the DLL libraries and are loaded to the PowerShell process during its launch. For themselves cmdlets as applications do not start.

Cmdlets names match the template "Verb-noun". The verb describes the action that we want to make, and the noun - the object that the action will be performed. For example, to clear the console screen, you must enter the Clear-Host command. You can view the available commands by entering the GET-COMMAND console.

Cups may have parameters. In general, it looks like this:

comandline name -Parameter1 -parameter2 Argument1 Argument2

Arguments are no name parameters.

How it works? For example, we have a DIR command that displays the contents of the directory.

DIR team work example

Suppose I lost a specific file. Let it be a certificate file by Photoshop. I remember exactly that the file name contains "Photoshop", and that this is a PDF file. As I remember, the file lies in this directory. I can display a list of all directory files as in the example above and search for the file manually. And I can apply the -filter parameter, which will display only those files that match a specific argument. As an argument there will be * Photoshop * .pdf. Asterisks around the word "Photoshop" stand because I do not remember the exact file name and pointing PowerShell to the fact that before and after "Photoshop" can stand any characters. I also point to look for the PDF file.

So, the search file was found. In the general form of cmdlets, it was designated that one cmdlet can have several parameters. In turn, the parameters do not always have arguments.

A little complicate our example. Let's say now I need to find the book of Christopher Dugurtesty. Team dir -Filter * Dougherty * .pdf I did nothing. It means that there are no books in this catalog, but I remember exactly that it is somewhere here, obviously, in subdirectories. In order to search and in subdirectories, add the -Recurse parameter.

The search will take a little longer, but the desired book will be found.

As you can see, the -Recurse parameter does not contain an argument. By themselves, the parameters can stand in any order, the main thing is to fully observe the logic when the required argument follows the parameter for which it is intended. So the team dir -Filter * Dougherty * .pdf -Recurse will work in the same way as dir -Recurse -Filter * Dougherty * .pdf.

The names of the parameters can be written in the abbreviated form, which is quite convenient for everyday work with the command line. The reduction should be clear to the interpriter, i.e. Do not allow twofold interpretations. For example, the -Recurse parameter can be reduced to simple -R, and reduction -Filter to -F will cause an error, because There is still a -Force parameter. In this case, you can cut -filter to -fi.

So, we got an idea of \u200b\u200bcelts. Next .

After moving to the Windows operating system 10, many users noticed the "Run PowerShell" button in the conductor interface. In this regard, a lot of questions appeared on the network, users interested in the Windows PowerShell program and what it is needed for. If you are also interested in this question, this material must help you.

Windows PowerShell is a scripting language and a program with a command line interface to perform these scripts. This language was released in 2006 as part of the second service pack for Windows XP and since then PowerShell is part of all Microsoft operating systems. In 2008, the second version appeared of this languageAnd starting with Windows 7 it is it. Windows PowerShell scripts have the PS1 extension and can be launched as BAT and CMD files familiar.

Windows PowerShell is a scripting language that was developed primarily for Microsoft business customers who need powerful tools to automate server management tasks and computers on windows database. The basis for this language was used by Platform.NET, developed by Microsoft since 2002.

Windows PowerShell allows you to automate a lot of variety of tasks. With it, you can manage files, services, processes, accounts and settings. PowerShell language understands many teams from ordinary Command line Windows (CMD), but it also has its own language consisting of its own commands, which are called celts here.

Cups (in English CmDlets) are formed by the Glagol-noun rule, for example, Get-Help. You can familiarize yourself with the basics of Windows PowerShell using the help (GET-HELP cmdlet). To obtain general information, simply enter the "Get-Help" command, enter "Get-Help-name-cmdlet" to receive a specific cmdlet. For example, if you enter the "Get-Help Get-Process" command, then we will receive a Get-Process cmot help.

How to run a Windows PowerShell program

Windows PowerShell program can be launched different ways. The easiest option is to simply use the search in the Start menu. To do this, open the Start menu, enter search query "Windows PowerShell", after which you open the program found.

You can also use a combination windows-R keys And enter the "PowerShell" command.

In Windows 10, the PowerShell program can be run from any folder. To do this, click on the "File" button in the upper left corner of the conductor and select "Run Windows PowerShell".

How to use Windows PowerShell

As we said, with the help of the PowerShell program, many routine tasks can automate operating system Windows. For example, we will demonstrate some of the features that this tool possesses, in order to become clear how to use it.

Cleaning basket. There is a special cmdlet to clean the basket, which is called "Clear-RecyClebin". This cmdlet is useful when writing scripts to maintain computers. When executing a cmdlet, you need to specify the disk on which you want to clear the basket. Example:

Clear-RecyClebin C:

In the screenshot below, it can be seen how this cmdlet is performed. After entering the "Clear-RecycleBin C:" command, a confirmation request appears. In order to continue the execution of the cmdlet, you need to enter the letter "Y" and press ENTER.

If you add "-Force" to the cmdlet "Clear-RecyClebin C:", then cleaning the basket is performed without a confirmation request. Screenshot at the bottom.

File archiving. For archiving and unpacking files, COMPRESS-ARCHIVE and EXPAND-Archive cmdlets are provided. For example, in order to archive the folder "C: \\ Test \\" to the archive "C: \\ Archive \\ Test2.zip" you need to execute the following cmdlet:

Compress-Archive -LiteralPath C: \\ Test \\ -DestinationPath C: \\ Archive \\ Test2.zip

As a result of the execution of the command shown above, the "Test2.zip" file appears in the "C: \\ Archive \\" folder in which the contents of the C: \\ Test \\ folder will appear.

List of cmdlets for Windows PowerShell

For Windows PowerShell, there are a huge number of different cmdlets and describe them all in one article will not work. Therefore, we suggest familiarizing yourself with the most sought after:

  • Get-help - receiving references;
  • UPDATE-HELP - refresh reference;
  • Get-Command - Search for cmdlets;
  • Get-Alias \u200b\u200b- search for pseudonyms for cmdlets;
  • Get-psdrive - view connected disks;
  • Get-Member - Viewing properties and methods that have an object;
  • Get-WindowsFeature - View information about available roles and server components;
  • Install-WindowsFeature (Analog Add-WindowsFeature) - Sets the roles or components to the desired server;
  • Uninstall-WindowsFeature (analogue of Remove-WindowsFeature) - removes the role or server component;
  • Get-History - view the history of the teams that were introduced in this session;
  • Get-Variable - view the list of variables and their values;
  • NEW-VARIABLE - Creating a new variable;
  • SET-VARIABLE - setting the value of the variable;
  • CLEAR-VARIABLE - removal of variable value;
  • Remove-variable - removing the variable and its values;
  • Format-List - view the result of the command as a list of properties, where in each line a separate property;
  • Format-Table - view the result of the command in the table format;
  • Format-Wide - View the result of the command in the form of a wide table, in which only one property is shown for each object;
  • Format-Custom - view the result of the command using the user view;
  • Export-CSV - data export to CSV format;
  • Import-CSV - import data from a CSV file;
  • Export-Clixml - Export data to XML format;

You can get a complete list of cmdlets for Windows PowerShell by running the Get-Command -Commandtype CmDlet cmdlet.