What is powershell used for?
Powershell is capable: 1. Can interact with the file system, start applications, and even manipulate applications; 2. Allows several commands to be combined and executed in files to achieve file-level reuse, that is It is said that you can create scripts; 3. You can make full use of .Net types and COM objects to simply interact with various systems and complete various complex and automated operations.
The operating environment of this tutorial: Windows 10 system, Dell G3 computer.
What is PowerShell?
PowerShell is a cross-platform task automation solution consisting of a command line shell, a scripting language, and a configuration management framework. PowerShell runs on Windows, Linux, and macOS.
Command Line Shell
PowerShell is a modern command shell that includes the best features of other commonly used shells. Unlike most shells, which only accept and return text, PowerShell accepts and returns .NET objects. The shell includes the following features:
Reliable command line history
-
Tab autocompletion and command prediction (see about_PSReadLine)
Support command and parameter aliases
Pipe for chaining commands
In-console help system, Similar to the Unix man page
#What can PowerShell do?
PowerShell is first of all a Shell, which defines a bunch of commands to interact with the operating system, especially the file system, and can start applications and even manipulate applications; secondly, PowerShell allows Several commands are combined and executed in a file to achieve file-level reuse, which means it has the nature of a script; third, PowerShell can make full use of .Net types and COM objects to simply interact with various systems and complete various tasks. A complex, automated operation.
1. Interact with the file system and run the application
Just like in Dos, type "dir" on the PowerShell interactive interface and press Enter. Displays subfolder and file information under the current folder.
PS D:\Projects\Practise\PowerShell> dir Directory: D:\Projects\Practise\PowerShell Mode LastWriteTime Length Name ---- ------------- ------ ---- d---- 1/23/2013 12:35 PM d1 d---- 1/23/2013 12:35 PM d2 -a--- 1/21/2013 8:38 PM 36314 alias.tx -a--- 1/21/2013 8:32 PM 241530 cmdlets. -a--- 1/18/2013 10:18 AM 888 errors.t
There are many commands like this, such as echo "Hello", cd...etc. From here it seems that it is a command line, realizing the functions of the original command line. But is PowerShell an enhanced version of the command line? Is it a superset of the command line? This is really not the case. I will talk about this issue specifically in the future.
Just like running applications in the command line, you can run applications in the interactive window of PowerShell, as follows:
PS C:\Users\v-lukez> notepad PS C:\Users\v-lukez>
If you want to have better control over the application Program, you can use the start command, as follows:
PS C:\Users\v-lukez> start notepad -WindowStyle Maximized PS C:\Users\v-lukez>
The above results can maximize the Notepad window. In fact, there are many similar commands, and more parameters mean more precise control.
2. Create a script
The automation of tasks is based on program files or executable script files. PowerShell also supports making a command list into a script file for execution. . The following is the content of the Hello.ps1 script file:
$a = "Hello" $a echo $a > a.txt dir a.txt
The execution results of the Hello.ps1 script file are as follows:
PS E:\> D:\Projects\Practise\PowerShell\Hello.ps1 Hello Directory: E:\ Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 1/30/2013 4:56 PM 16 a.txt
You may find Yes, PowerShell script files have a .PS1 extension. The above script is very simple: first define a variable, then output the result of this variable, then write the value of this variable to the file a.txt, and finally output the attribute information of this file. From this point alone, PowerShell scripts are very similar to Batch files. But in reality, PowerShell can do much more.
PowerShell scripts support custom functions, just like we do in programming languages. funcDemo.ps1 gives an example of writing a function in a PowerShell script:
#funcDemo.ps1 function SayHello ($name) { echo "hello $name" } SayHello "Luke"
The result of the script is "Hello Luke".
In addition, regarding the running order of statements within the PowerShell script, here is a brief explanation: In addition to function definitions, commands or function calls in the script (actually equivalent to executing commands) will be executed sequentially; The statement will only be executed when the function is called.
3. Utilizing .Net types and COM objects
Being able to utilize .Net types and COM objects is the biggest feature of PowerShell, which allows PowerShell to maximize the use of existing It has resources and can easily recruit .Net and COM programmers to its staff.
Simple type:
[int]$a = 10 [String]$b = 10
.Net type
$Message = new-object Net.Mail.MailMessage("me@source.com","you@destination.com", "Subject", "Here is some email")
COM object
$myWord = new-object -comobject Word.Application
After creating .Net or COM objects, you can use the properties and methods of these objects to complete more complex operations.
To end this article, let me sum it up in one sentence: PowerShell eats very little and does a lot of work. It is one of the daily essential tools for Windows administrators. If you are passing by, don’t miss it. . .
How to open and run PowerShell
1. Win menu key R:
2. The running window pops up as follows:
3. Enter PowerShell in the input box and press Enter or click OK:
4. After typing, the PowerShell command window will pop up. Congratulations, you have done it. You can directly enter the command line in it. Please refer to the following:
For more related knowledge, please visit FAQ column!
The above is the detailed content of What is powershell used for?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



What is an ISO file? An ISO file is a file that contains an exact copy of an optical disc, such as a DVD or CD. This type of disc image can be installed on your computer and appear as if you have an optical drive connected to your computer and a CD or DVD containing data inserted into the drive. ISO files can also be used to burn new copies of the DVDs or CDs from which they were created, or simply to contain a large number of files in a single file that is easy to download. ISO files are often quite large; when you're done with them, you'll most likely want to

Initial PowerShell, first let's understand the concept: PowerShell can be regarded as an upgraded version of cmd (bat scripting language), which is a scripting language on the Windows platform. It is object-oriented and closely related to .NetFrameWork. It can also be thought of as the bashshell on Windows. Windows PowerShell is a command line shell and scripting environment that enables command line users and script writers to take advantage of the power of the .NET Framework. It introduces a number of very useful new concepts, further extending what you get in the Windows Command Prompt and WindowsHost environments

Many users have reported issues with Windows PowerShell stopping working or not opening at all. One of the most common reasons for seeing the PowerShell has stopped working message is that there is a hidden virus on your computer. This in turn will slow down your system and other processes on the system will stop functioning. The error message does not provide any information about the cause of this problem, making it difficult to resolve. If you are annoyed with PowerShell not running or opening issues on your PC, then this article is for you. In this article, we have discussed some of the solutions you can use to fix this error. Fix 1 – Disable and re-enable Windows PowerShell 1. Use Ctr

How to Open PowerShell as Administrator on Windows 11 Running PowerShell with elevated or administrator-level permissions allows you to run commands that bypass Windows file protection, such as those used for Windows installation files. You can run PowerShell by opening PowerShell directly or by opening the new Windows Terminal application, which uses PowerShell to run commands by default. Open PowerShell as administrator on Windows 11: Open the start menu and type powershell or terminal. from the right

How to Enable or Disable an Administrator Account on Windows 11 Using PowerShell One of the quickest ways to enable an administrator account on Windows 11 is to use PowerShell. You can also use the newer Windows Terminal or, if you prefer, the older Command Prompt (cmd) tool. You need to make sure you run these commands from a user account that already has administrator rights. If you are using a standard user account, you will need to switch to another user account to run this tool. To enable an administrator account using PowerShell on Windows 11: Open by clicking the Start button or pressing the Windows key

Do you see this error message "Add-AppxPackage: Deployment failed with HRESULT: 0x80073D02, The package cannot be installed because the resource it modifies is currently in use. Error 0x80073D02..." in PowerShell when you run the script? As the error message states, this does occur when the user attempts to re-register one or all WindowsShellExperienceHost applications while the previous process is running. We've got some simple solutions to fix this problem quickly. Fix 1 – Terminate the experience host process You must terminate before executing the powershell command

Click to enter: ChatGPT tool plug-in navigation list Git is one of the most popular version control systems, which allows you to track all changes made to files so that you can easily revert to an earlier version if needed. Git allows you to have both a local repository and a remote repository, encouraging others to collaborate and centralizing all those changes into a single source. Prerequisites for installing Git on Windows 11 Before we begin, there are some prerequisites for installing Git on Windows. Here they come: Administrator rights to your Windows account to access a command line tool (e.g. CMD or PowerShell) Git username and password (optional) Your favorite text editor WSL on Ubuntu

Differences: 1. When running Cmd, it only takes up less than 1M of memory; when using PowerShell, it takes up about 20M of memory. 2. Cmd does not support syntax highlighting, but PowerShell does. 3. When using Cmd to run some more complex and time-consuming commands, when you drag the command line window at will, the content in the window can still remain the same; but PowerShell cannot. 4. Cmd can only use commands in the .net library, nor can it use Linux commands; PowerShell can.