Get started Bring yourself up to speed with our introductory content.

25 basic PowerShell commands for Windows administrators

Getting started with PowerShell or just need a quick refresher? This tip lists the most common PowerShell commands, with details on when to use them.

Even though Windows PowerShell has been around for a while, there are plenty of administrators who might not venture...

willingly into the command line familiar with what a PowerShell cmdlet is. But, as Microsoft expands the functionality of PowerShell, administrators should take an interest in understanding the fundamentals of its capabilities.

Let's look at 25 basic PowerShell commands you can execute tasks with. Not only are the tasks themselves common, but the structures of the commands show off the syntax and structure of other PowerShell commands. These basic PowerShell commands should get you started on the path to becoming a master.

Common entries (just to get started)

1. cd hkcu:

Navigate the Windows Registry like the file system.

2. dir –r | select string "searchforthis"

Search recursively for a certain string within files.

3. ps | sort –p ws | select –last 5

Find the five processes using the most memory.

4. Restart-Service DHCP

Cycle a service (stop, and then restart it) like Dynamic Host Configuration Protocol (DHCP).

5. Get-ChildItem – Force

List all items within a folder.

6. Get-ChildItem –Force c:\directory –Recurse

Recurse over a series of directories or folders.

7. Remove-Item C:\tobedeleted –Recurse

Remove all files within a directory without being prompted for each.

8. (Get-WmiObject -Class Win32_OperatingSystem -ComputerName .).Win32Shutdown(2)

Restart the current computer.

Collecting information

9. Get-WmiObject -Class Win32_ComputerSystem

Get information about the make and model of a computer.

10. Get-WmiObject -Class Win32_BIOS -ComputerName .

Get information about the BIOS of the current computer.

11. Get-WmiObject -Class Win32_QuickFixEngineering -ComputerName .

List installed hotfixes -- quick fix engineering updates (QFEs), or Windows Update files.

12. Get-WmiObject -Class Win32_ComputerSystem -Property UserName -ComputerName .

Get the username of the person currently logged on to a computer.

13. Get-WmiObject -Class Win32_Product -ComputerName . | Format-Wide -Column 1

Find just the names of installed applications on the current computer.

14. Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName . | Format-Table -Property IPAddress

Get IP addresses assigned to the current computer.

15. Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName . | Select-Object -Property [a-z]* -ExcludeProperty IPX*,WINS*

Get a more detailed IP configuration report for the current machine.

16. Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "DHCPEnabled=true" -ComputerName .

Find network cards with DHCP enabled on the current computer.

17. Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=true -ComputerName . | ForEach-Object -Process {$_.EnableDHCP()}

Enable DHCP on all network adapters on the current computer.

Software management

18. (Get-WMIObject -ComputerName TARGETMACHINE -List | Where-Object -FilterScript {$_.Name -eq "Win32_Product"}).Install(\\MACHINEWHEREMSIRESIDES\path\package.msi)

Install an MSI package on a remote computer.

19. (Get-WmiObject -Class Win32_Product -ComputerName . -Filter "Name='name_of_app_to_be_upgraded'").Upgrade(\\MACHINEWHEREMSIRESIDES\path\upgrade_package.msi)

Upgrade an installed application with an MSI-based application upgrade package.

20. (Get-WmiObject -Class Win32_Product -Filter "Name='product_to_remove'" -ComputerName . ).Uninstall()

Remove an MSI package from the current computer.

Machine management

21. Start-Sleep 60; Restart-Computer –Force –ComputerName TARGETMACHINE

Remotely shut down another machine after one minute.

22. (New-Object -ComObject WScript.Network).AddWindowsPrinterConnection("\\printerserver\hplaser3")

Add a printer.

23. (New-Object -ComObject WScript.Network).RemovePrinterConnection("\\printerserver\hplaser3 ")

Remove a printer.

24. enter-pssession TARGETMACHINE

Enter into a remote PowerShell session -- you must have remote management enabled.

25. invoke-command -computername machine1, machine2 -filepath c:\Script\script.ps1

Use the PowerShell invoke command to run a script on a remote server.

Bonus command

26. Stop-Process -processname calc*

To dismiss a process, you can use the process ID or the process name. The -processname switch enables the use of wildcards. This is how to stop the calculator.

Windows scripting school

Need to brush up on your PowerShell scripting know-how? It's time to go to school. Check out the archives from Christa Anderson's scripting column.

Next Steps

Key PowerShell commands for Exchange Server

Get Exchange under control with help from PowerShell

Enlist PowerShell for Exchange management tasks

Build a PowerShell cheat sheet

Dig Deeper on Windows Server storage management

Join the conversation

6 comments

Send me notifications when other members comment.

Please create a username to comment.

What are some ways you use PowerShell commands to manage users and systems in your environment?
Cancel
Great article jammed with useful information. Nice to have all the PS commands in once place.

Cancel
Great and useful information.Excellent ,Thank you.
Cancel
Get-WmiObject -Class Win32_QuickFixEngineering -ComputerName

I am new to PScript, Please guide me that use this command to get latest updates only

i have tried to get last 10 but got error.
Get-WmiObject -Class Win32_QuickFixEngineering -ComputerName select -last 10
Cancel

If the command you used is exactly as posted, you left out self-reference (the . after the -ComputerName), and you also left out a pipe (|) before the Select.

The example below goes further by sorting the results by the InstalledOn property and formats the table output width automatically.


Get-WmiObject -Class Win32_QuickFixEngineering -ComputerName . | Sort -P InstalledOn | Select -Last 10 | Format-Table -Auto


Cancel
(Get-WmiObject -Class Win32_Product -ComputerName . -Filter "Name='name_of_app_to_be_upgraded'").Upgrade(\\MACHINEWHEREMSIRESIDES\path\upgrade_package.msi)

So much more elegant and concise than:

apt get update

Linux with it's cryptic commands and syntax. Feh! 
Cancel

SearchServerVirtualization

SearchCloudComputing

SearchSQLServer

SearchEnterpriseDesktop

SearchVirtualDesktop

Close