PowerShell is a versatile and powerful command-line shell and scripting language designed for system administration tasks. It provides a comprehensive set of cmdlets (pronounced 'command-lets') for performing a wide range of tasks, from simple file operations to complex system configurations. This article presents a comprehensive guide to some of the most commonly used PowerShell commands.
1. Get-Help: This cmdlet displays information about PowerShell commands and concepts. To get help for a specific command, type Get-Help followed by the command name, e.g., Get-Help Get-Process.
2. Get-Command: This cmdlet retrieves all the commands available in the current session, including cmdlets, functions, and aliases. To retrieve commands with a specific name, use the -Name parameter, e.g., Get-Command -Name *process*.
3. Get-Member: This cmdlet displays the properties and methods of an object. To use it, pipe an object to Get-Member, e.g., Get-Process | Get-Member.
4. Get-Service: This cmdlet gets the services on a local or remote computer. To get a specific service, use the -Name parameter, e.g., Get-Service -Name "Spooler".
5. Stop-Service: This cmdlet stops one or more running services. To stop a specific service, use the -Name parameter, e.g., Stop-Service -Name "Spooler".
6. Start-Service: This cmdlet starts one or more stopped services. To start a specific service, use the -Name parameter, e.g., Start-Service -Name "Spooler".
7. Restart-Service: This cmdlet restarts one or more services. To restart a specific service, use the -Name parameter, e.g., Restart-Service -Name "Spooler".
8. Get-Process: This cmdlet gets the processes running on the local computer. To get a specific process, use the -Name parameter, e.g., Get-Process -Name "notepad".
9. Stop-Process: This cmdlet stops one or more running processes. To stop a specific process, use the -Name parameter, e.g., Stop-Process -Name "notepad".
10. Get-Item: This cmdlet gets the item at the specified location. To use it, provide the path to the item, e.g., Get-Item -Path C:\Windows\System32\notepad.exe.
11. Get-ChildItem: This cmdlet gets the items in one or more locations. To use it, provide the path to the parent item, e.g., Get-ChildItem -Path C:\Windows\System32.
12. Copy-Item: This cmdlet copies an item from one location to another. To use it, provide the path to the source item and the destination path, e.g., Copy-Item -Path C:\Windows\System32\notepad.exe -Destination C:\Temp.
13. Move-Item: This cmdlet moves an item from one location to another. To use it, provide the path to the source item and the destination path, e.g., Move-Item -Path C:\Temp\notepad.exe -Destination C:\Windows\System32.
14. Remove-Item: This cmdlet removes an item from the specified location. To use it, provide the path to the item, e.g., Remove-Item -Path C:\Temp\notepad.exe.
15. New-Item: This cmdlet creates a new item in the specified location. To use it, provide the path to the parent item and the type of item to create, e.g., New-Item -Path C:\Temp -Name "New Folder" -ItemType Directory.
16. Clear-Host: This cmdlet clears the host program's display and resets the cursor position to the upper-left corner of the host program's window. To use it, simply type Clear-Host.
17. Get-Content: This cmdlet gets the content of the item at the specified location. To use it, provide the path to the item, e.g., Get-Content -Path C:\Temp\example.txt.
18. Set-Content: This cmdlet sets the content of an item at the specified location. To use it, provide the path to the item and the content, e.g., Set-Content -Path C:\Temp\example.txt -Value "Hello, World!".