Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the hands-on experiments of Windows PowerShell?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

What are the hands-on experiments of Windows PowerShell? I believe many inexperienced people are at a loss about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

1. View all pre-set aliases (aliase) in Powershell?

PS C:\ > export-alias-path alias.csv

Description:

This command exports the current alias information to a file named Alias.csv in the current directory.

two。 Which Cmdlet command can convert the output of other Cmdlet commands to HTML?

Command: ConvertTo-Html

Application:

PS C:\ > get-process | convertto-html-property Name, Path, Company-title "Process Information" > proc.htm; ii proc.

Htm

These commands create and open a HTML page that lists the name, path, and company of the process on the local computer.

The first command uses Get-Process cmdlet to get the object used to represent the process running on the computer. This command uses the pipe operator (|) to send the process object to C

OnvertTo-Html cmdlet .

This command uses the Property parameter to select the three properties of the process object to include in the table. This command uses the Title parameter to specify the title of the HTML page. The command also

Use the redirect operator (>) to send the generated HTML to a file named Proc.htm.

The second command uses Invoke-Item cmdlet (alias ii) to open Proc.htm in the default browser. The two commands are separated by a semicolon (;).

3. Which CMdlet command can redirect output to a file (file) or to a printer (printer)?

Command: out-file

Application:

PS C:\ > $a = get-process

PS C:\ > out-file-filepath C:\ Test1\ process.txt-inputobject $a-encoding ASCII-width 50

These commands send a list of processes on the computer to the Process.txt file. The text is encoded in ASCII format so that search programs such as Findstr and Grep can read the text. By default, Out-File uses the Unicode format.

The first command takes a list of processes and stores them in the $a variable. The second command uses Out-File cmdlet to send the list to the Process.txt file.

This command uses the InputObject parameter to specify that the input is in the $a variable. It uses the Encoding parameter to convert the output to ASCII format. It uses the Width parameter to limit each line in the file to 50 characters. Because the output line is truncated at 50 characters, the rightmost column of the process table is omitted.

Command: out-Printer

Application:

PS C:\ > $h = get-help-full get-wmiobject

PS C:\ > out-printer-inputobject $h

These commands print the help topic for the full version of Get-WmiObject. The first command uses Get-Help cmdlet to get the full version of Get-WmiObject

And store it in the $h variable The second command sends the content to the

Recognize the printer. It uses the InputObject parameter to pass the value of the $h variable to Out-Printer.

4. Which Cmdlet command can operate a process (process)? (hint: remember, all Cmdlet commands contain a noun)

Get-Process Cmdlet Microsoft.PowerShell.M... Gets the process running on the local or remote computer.

Start-Process Cmdlet Microsoft.PowerShell.M... Start one or more processes on the local computer.

Stop-Process Cmdlet Microsoft.PowerShell.M... Stop one or more running processes.

Wait-Process Cmdlet Microsoft.PowerShell.M... Wait until the process stops before accepting more input.

5. Which Cmdlet command can you use to write data to the transaction log (log)?

Answer:

Write-EventLog

Application:

PS C:\ > write-eventlog-computername Server01-logname Application-source MyApp-eventID 3001-message "MyApp added"

A user-requested feature to the display. "

This command writes an event from the MyApp source to the application event log on the remote computer Server01.

6. You must know that aliases are nicknames for Cmdlet commands. Which Cmdlet can be used to create, modify, or import aliases (aliases)?

Create: New-Alias or Set-Alias

Modify: Set-Alias

Import: Import-Alias

Application:

Create:

PS C:\ > new-alias list get-childitem

This command creates an alias named list to represent Get-ChildItem cmdlet.

Import:

PS C:\ > import-alias test.txt

This command imports alias information from a file named test.txt.

Modify:

PS C:\ > set-alias list get-location

This command associates the alias "list" with Get-Location cmdlet. If "list" is an alias for another cmdlet, this command changes its association so that

It is used only as an alias for Get-Location

This command uses the same format as the command in the previous example, but omits the optional parameter names-Name and-Value. When parameter names are omitted, the values of these parameters must be specified by the

The order of appears in the command. In this example, the value of-Name ("list") must be the first parameter, the value of-Value

("get-location") must be the second parameter.

7. How to ensure that your input in shell is in a transcript, and how to save the script to a text file?

Command:

Start-Transcript > c:\ transcript.txt

This command can generate a transcript.txt document in the C disk directory, indicating the location where the current script is stored.

8. It can take a long time to retrieve all entries from the security event (event) log. How do you get only the last 10 records?

Find a solution

9. Is there a way to get a list of services (services) installed on a remote computer?

Command:

Get-Service

Application:

PS C:\ > get-service-computername Server02

This command gets services on the Server02 remote computer.

Because the ComputerName parameter of Get-Service does not use Windows PowerShell remoting, even if the computer is not configured in Windows PowerShe

Remote processing in ll, you can also use this parameter.

How many characters is the default width size of each line of records output from the 11.Out-File command to the file? Is there a parameter that can modify this width?

-Width

Specifies the number of characters in each line of the output. Any extra characters will be truncated without line wrapping. If this parameter is omitted, the width is determined by the characteristics of the host. Windows PowerShe

The default value for the ll console is 80 (characters).

Is it necessary? False

Location? Named

Default value 80

Do you accept pipe input? False

Do you accept wildcards? False

twelve。 Is there a parameter that prevents the Out-File command from overwriting existing files?

-NoClobber []

The existing file will not be overwritten (replacing its contents). By default, if a file exists in the specified path, Out-File will overwrite the text without warning

Pieces. If both Append and NoClobber are used, the output is appended to the existing file.

After reading the above, have you mastered the methods of Windows PowerShell's hands-on experiments? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report