In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to use PowerShell. The introduction in this article is very detailed and has certain reference value. Interested friends must read it!
What is PowerShell?
PowerShell is first and foremost a Shell that defines a bunch of commands that interact with the operating system, especially the file system, to launch applications and even manipulate them. PowerShell also allows several commands to be combined and executed in a file to achieve file-level reuse, that is, the nature of scripts. PowerShell makes full use of. Net types and COM objects to simply interact with a variety of systems and complete complex, automated operations. It can also be seen as an extension of cmd.exe, which Microsoft introduced to make shell functions as powerful as Linux systems.
1. How to Start PowerShell
PowerShell is generally integrated in Windows systems, and there are several startup methods as follows:
a) Direct Start Menu-> All Programs-> Windows PowerShell -> Windows PowerShell (path may vary depending on system). After activation, the effect is as follows:
b) Start Menu-> Run-> Enter "PowerShell." After successful startup, it is the same as the above picture.
Command Prompt-> PowerShell. After activation, the effect is as follows:
After successful startup, you can enter the command to be executed in it, which is the interactive interface of PowerShell.
2. How to run programs, scripts, and existing software
If you've been developing with other tools a lot, there may be executables, Perl scripts, batch files, etc., that you can run directly with PowerShell if you don't want to give up.
a) Run programs, scripts, batch files or other executable files under the system path, you can directly enter the file name to run. For example, if I put a Test.cmd file under "C:\Windows\System32," I can run it as follows:
b) If there are spaces in the file name or path, you need to enclose the command with quotation marks and add the symbol (&) before it. This is called calling operation:
c) To run commands in the current directory, you need to prefix the filename with.\, For example:
d) To run commands in the current directory, and the command name or path has spaces, you need to add both symbols (&) and ('):
3. Run PowerShell commands
In addition to supporting traditional Windows executables, PowerShell also introduces a powerful new command called cmdlets. All cmdlet command rules follow the verb noun syntax structure, such as Get-Command, Get-Content, etc. The following Get-Command command means to get all the command sets containing Process:
When entering "Get-Command -Name *Process", instead of entering the full command name, PowerShell will help you use the Tab key to automatically complete the command input, including the name of the command and the name of the parameter, such as: Get-Comm -N *Process.
4. How to find the specified command and command details
a) If you want to perform a task in PowerShell, but do not know what command to use, then you need to find a command, you can use the Get-Command command, and it supports wildcards. Examples are as follows:
b) To see what a command does, use the Get-Help command. Examples are as follows, and you can also specify parameters-Detailed, -Full, -Examples.
c) Since PowerShell can use objects in the. NET Framework, to view the properties and methods of an object, you can use the Get-Member command. Examples are as follows:
5. How to call PowerShell scripts externally
Sometimes you may need to invoke PowerShell scripts from batch files, scheduled tasks, or other non-PowerShell programs, syntax: PowerShell "& 'full path of the script' arguments". The following example is a call to PowerShell from CMD.
6. How to know the status of the last executed command
PowerShell provides two variables that detect the success of the last command executed: $lastExitCode and $?.
$lastExitCode: numeric variable that returns the exit code or error level returned by the last script or application execution:
$?:Boolean variable that returns the success or failure of the last command executed:
Variable $? Using a more generic way to describe the state of the last application exit, PowerShell sets $? False:
Application exit code is non-zero;cmdlet or script outputs error information;cmdlet or script caught a termination error or exception.
When the command is executed without errors, PowerShell sets $? Variable is True.
7. How to Calculate Command Execution Time
If you want to calculate the execution time of a command, you can use the Measure-Command command as follows:
8. Understanding command aliases
PowerShell some built-in commands have aliases, convenient memory and input, you can use Get-Help command to view aliases, as follows Get-Children command has three aliases: gci, ls and dir, input any one can enumerate the current directory.
9. How to Use the Administration Console History Command
In the PowerShell window, press the up and down arrow keys to find the history command to invoke, or you can run Get-History command to find it and invoke it in Invoke-History Id mode:
10. How to redirect output
If you want to output the results to a file, you can save the output of the command to a file using the Out-File command or the redirect operator:
11. How to log PowerShell session full text
If you want to generate a record of the current session, run the Start-Transcript command, which is based on the current system time. If you want to stop, run Stop-Transcript:
12. How to display object attributes as lists or tables
Using Format-List and Format-Table commands, look directly at the example:
13. How to connect systems in a virtual machine
The above is all the content of this article "How to use PowerShell", thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.