Summary of 25 commonly used PowerShell commands

Source: Internet
Author: User

Although Windows PowerShell has been there for some time, the administrator of the custom command line might be interested in understanding the basics of PowerShell functionality.

Let's take a look at the 25 most common tasks that can be done by Windows PowerShell. Not only are these tasks simple, but the command schema and other PowerShell commands that display statements are also simple. Mastering these basic commands is the only way to become a PowerShell specialist.

Entry level

1. Operate Windows REGISTRY--CD HKCU like a file system:
2. Recursively search for a string in a file--dir–r | Select string "Searchforthis"
  
3. Use memory to find five processes--ps | Sort–p ws | Select–last 5
4. cycle (stop, then restart) a service, such as Dhcp--restart-service DHCP
5. List all entries in the folder--get-childitem–force
6. Recursive series of directories or folders--get-childitem–force C:\directory–recurse
7. Remove all files in the directory without requiring a single removal of--remove-item C:\tobedeleted–recurse
8. Restart the current computer--(Get-wmiobject-class win32_operatingsystem-computername.). Win32Shutdown (2)

Collect information

9. Get computer composition or model information--get-wmiobject-class Win32_ComputerSystem
10. Obtain BIOS information for the current computer--get-wmiobject-class Win32_bios-computername.
11. List the installed hotfixes (such as QFE or Windows Update files)--get-wmiobject-class Win32_quickfixengineering-computername.
12. Get the user name of the user who is currently logged on to the computer--get-wmiobject-class Win32_computersystem-property username-computername.
13. Get the name of the app that is installed on the current computer--get-wmiobject-class Win32_product-computername. | Format-wide-column 1
14. Get the IP address assigned to the current computer--get-wmiobject-class Win32_networkadapterconfiguration-filter ipenabled=true-computername. | Format-table-property IPAddress
15. Get the current machine detailed IP configuration report--get-wmiobject-class win32_networkadapterconfiguration-filter ipenabled=true-computername. | Select-object-property [a-z]*-excludeproperty ipx*,wins*
16. Locate the network card that is enabled on the current computer using DHCP--get-wmiobject-class win32_networkadapterconfiguration-filter "Dhcpenabled=true"- ComputerName.
17. Enable Dhcp--get-wmiobject-class Win32_networkadapterconfiguration-filter ipenabled=true on all network adapters on the current computer- ComputerName. | foreach-object-process {$_. EnableDHCP ()}

Software Management

18. Installing the MSI package on a remote computer--(Get-wmiobject-computername targetmachine-list | Where-object-filterscript {$_. Name-eq "Win32_Product"}). Install (\\MACHINEWHEREMSIRESIDES\path\package.msi)
19. Upgrade the installed app with the MSI-based app update package-(Get-wmiobject-class win32_product-computername.-filter "Name=" Name_of_app_to_be_ Upgraded ' "). Upgrade (\\MACHINEWHEREMSIRESIDES\path\upgrade_package.msi)
20. Remove the MSI package from the current computer--(Get-wmiobject-class win32_product-filter "name= ' Product_to_remove '"-computername.). Uninstall ()
Machine Management
21. One minute after the remote shutdown of another machine--start-sleep 60; Restart-computer–force–computername Targetmachine
22. Add Printer--(New-object-comobject wscript.network). AddWindowsPrinterConnection (\\printerserver\hplaser3)
23. Remove the printer-(New-object-comobject wscript.network). Removeprinterconnection ("\\printerserver\hplaser3")
24. Go to PowerShell session--invoke-command-computername Machine1, Machine2-filepath c:\Script\script.ps1

Summary of 25 commonly used PowerShell commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.