Windows PowerShell Basics (Creating and Running Scripts

06/20/2018 windows | for beginners

Many of the instructions on this site suggest running PowerShell, usually as an administrator, as one of the first steps. Sometimes novice users ask in the comments how to do this.

This guide details ways to open PowerShell, including as an administrator, in Windows 10, 8 and Windows 7, as well as video instructions where all these methods are clearly shown. You may also find it useful: Ways to open Command Prompt as an administrator.

Methods for opening a PowerShell snap-in

Powershell is developing very well and with the release of Windows 10 it has already received version 5, but our topic is different. So how to open powershell? Everything is simple if in Windows XP, then nothing. Since it is delivered separately, in all subsequent releases it comes as a built-in component. The most universal way to open powershell is to click

Win+R and enter powershell

By pressing enter, the PowerShell console will launch, the only problem is that it will not open as administrator. And as a result, many commands will not be executed; below we will see how to do this on behalf of the administrator.

How to run windows powershell as administrator in Windows 8.1 and Windows 7

You can open Windows Powershell through Start. In Windows 8.1, Windows 2012 R2, go to System Tools - Windows and right-click and select Run as administrator.

In Windows 7 and Windows 2008 R2 it looks like this Start > Accessories > Windows PowerShell

You can also create a shortcut in the task item and right-click on it and select the appropriate item

It would be convenient if PowerShell always opened as administrator, let's implement it. This is done the same way in all versions of Windows. Opening the control panel

Next go to Administration > Windows PowerShell (x86)

Right-click on it and select Properties. You can immediately see the path to the file where it is located in the system.

Click the “Advanced” button. You will see additional properties. where you need to check the box Run as administrator.

Everything is very simple. I am sure that now you will not have a question about how to open Windows Powershell. Another useful thing is to change the font in the powershell window.

Removal

The “rmdir” command or its shortened version “rm” allows you to delete folders and their contents. After that the parameters are written, then the path.

If you want to delete an empty “Example folder” directory, write it like “rmdir “C: Example folder””.

If the “Example folder” is not empty, it contains subfolders/files, in order to delete everything together, you should enter the “/s” key after the command. The key is entered after “rmdir”, but before the destination address. That is, the entry will look like this: “rmdir /s “C:Example folder””. After typing the command, you will see a confirmation request, select “y”, which means that you agree to delete (“yes”).

To prevent the confirmation request from constantly appearing, you can immediately register the “/q” key. It fits after the "/s".

You can list what you want to delete separated by a space. Let’s say that inside “Test” you no longer need folders 2 and 3, which means you write the command: “rmdir /s /q “C:Test1” “C:Test2” “C:Test3”. If you are already in the “Test” directory, you can enter the shortened version: “rmdir /s /q 1 2 3”.

How to Open PowerShell from the Start Button Context Menu in Windows 10

Microsoft is increasingly focusing on its powerful language (PowerShell) from the command line, and this is logical, since its capabilities for managing operating systems of the Windows family are almost limitless, if not more than in the graphical interface. Starting with version 1709 of Windows 10, in the context menu, PowerShell replaced the usual cmd. Right-click on the start button in Windows 10 and from the context menu, select the appropriate item:

  1. Windows PowerShell
  2. Windows PowerShell (administrator) is exactly the mode with maximum rights in Windows 10.

Launch Windows PowerShell using Search in Windows 10

In Windows 10 and older versions, you can find the PowerShell shell using a regular search; there is a special section for this. Click next to the Start button, the magnifying glass icon. In the search form that opens, enter the word PowerShell. You will search for all options, among which you will find the shell. If you right-click on it, you can open it as an administrator.

Out of the box run

Press Windows + R to open the Run dialog box and then type "powershell" into the text box. You can either click OK (or press Enter) to open a regular PowerShell window, or press Ctrl + Shift + Enter to open an elevated PowerShell window.

Launching Windows PowerShell from the Start menu in Windows 10

To open PowerShell from the Start menu, open it and find the Windows PowerShell item, it will be in the form of a folder, open it and run the appropriate version.

If you right-click, you can run the Vershel shell as an administrator with administrator rights.

Additional and generic shell launch methods

There are also very specific methods for opening a shell with a powerful language from Microsoft. The most clumsy one is to simply find the executable file and run it directly from its location on the system. Let's go to your Windows 10 along the following path:

C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows PowerShell

As a result, you will see a folder with shortcuts that are present in the Start menu, you can launch them.

You can also run the original executable file, which is located along the path:

C:\Windows\System32\WindowsPowerShell\v1.0

And by right-clicking on it, you can download it as an administrator, with maximum rights.

You can also launch Windows PowerShell from the command line window; to do this, simply enter the magic word in it and press Enter.

Well, let me also remind you of the method for launching a new task from the “Task Manager” snap-in. Open "Task Manager", select the menu item "File - Run new task"

In the window that appears, enter PowerShell.

Well, the last method I know of is to launch PowerShell through Windows 10 Explorer, to do this, open Explorer, select the menu item “File - launch Windows PowerShell”, there will be both modes.

Running PowerShell as a different user

The responsible administrator always has two accounts, the first one has the minimum rights of an ordinary user for everyday tasks. The second one already has the necessary administrative privileges, from which he configures servers and everything related. Windows operating systems have functionality that allows you, while in the session of one user, to launch an application on behalf of another, who has more advanced rights. So, in a regular user session, the system administrator launches PowerShell on behalf of a user with different rights and calmly manages what he wants.

To run PowerShell as another user, you need to hold down the SHIFT button, then right-click on the PowerShell icon and select “Run as another user” from the context menu.

Enter the login and password for the account you need. As a result, the shell will work in the context of another user.

You can also launch a new PowerShell window from the current user window, but with new rights, to do this, enter the command:

start powershell -credential ""

In the account request window, indicate the login and password for the account that has the rights you need for your further work.

Creation

To create a new folder, type “mkdir”, or simply “md” for short. Next, write down the path to it and its name. For example, in the root of drive C you need to create a subfolder “Russian” in the existing “Test”, which means you type sequentially “mkdir “C:TestRussian””.

You can create several new folders at once; then specify the paths separated by a space or names. Let's say that in the same “Test” subfolders 1, 2, 3 are required. If you are already in the root of the C-drive, type “mkdir “Test 1” “Test 2” “Test 3””. If you are already in “Test”, you can use a shortened version of the command: “mkdir 1 2 3”. But do not forget: if there are spaces in the names, they will need to be enclosed in quotation marks.

Launching PowerShell via keyboard shortcut

One of the convenient methods for launching PowerShell, if used very often, is to assign a hotkey combination to it, which, when pressed, launches the shell. It's done, it's very simple. Open the PowerShell properties Shortcut ” tab, find the “ Shortcut ” item, by default it has the status no.

Select it and press the Shift or Ctrl, or CTRL+SHIFT key, as a result of which you will substitute the construction for the future combination and also press any key from the letter range, in my example it turned out CTRL + SHFT + C. This is the combination I will call your PowerShell. Save the settings. I also note that you can easily cancel it or change it to another.

I'm trying to enter the shortcut combination CTRL + SHFT + C, as I see everything works great.

Options

Strictly speaking, in the spirit of consistent naming in PowerShell, all parameter names passed to a cmdlet must follow the "-" character. However, for ease of writing, the names of some parameters can be omitted. For example, to access help for the Get-Content cmdlet instead of specifying the full

Get-Help –name Get-Content

you can enter the command

Get-Help Get-Content

The parameter may have any value (in the example just given, the value of the name parameter was Get-Content) or may not have any value. In this case, it is analogous to a switch for some functionality of the command. For example, if you want to get complete information about the Get-Content cmdlet, enter

Get-Help Get-Content –Detailed

Powershell properties

Powershell changing the font is very simple, go to the Font tab in the properties, where you can set the size from 5 to 72.

You can also get to properties from the utility window itself, click on the icon in the upper left corner and select properties

Here the font settings are slightly different, and as they change, the size of the console also changes.

On the Colors tab, you can set the font color in Powershell and the window itself. By making it black, for example, like the command line.

Transitions

While working through the command line, you want to change to a different directory. The "chdir" command will help you, allowing you to go to another location. Or simply go to the section, as described above in this article, using the “cd” command.

To move to a subdirectory, it is not necessary to indicate the full address if you are in the parent directory. Let's say you are in "ProgramFile", how do you go to the "Skype" folder in the command line? There is no need to specify the full path: “cd “C:ProgramFilesSkype””; Just indicate the name of the subdirectory: “cd “Skype””.

To go back to the parent directory, type “cd “ProgramFiles””.

If you need to change the location drive, add the “/D” key, for example, from drive C: you need to go to D:, enter “cd /D d:/”.

Rating
( 1 rating, average 4 out of 5 )
Did you like the article? Share with friends:
For any suggestions regarding the site: [email protected]
Для любых предложений по сайту: [email protected]