Powershell Top 10 Commands to help you to learn Powershell quickly, one has to learn these commands and experiment in practical life, these commands definitely help you to speed up your learning journey.
There are many commands available in Powershell that allow administrators to automate the jobs. However, I choose these 10 Powershell commands are very important and commonly used in every script, let’s begin and learn.
- Get-help
- Get-member
- Get-wmiobject
- Show-command
- Invoke-command
- Enter-Pssession
- Get-command
- Copy-item
- Converto-html
- Remove-item
Powershell Get-Help
The command name itself indicates help, correct this command displays information of any command that you request or query, it gives the information command description, functions, workflows, providers, aliases and example scripts.
This Get-help command displays the information of any other Powershell command based on its library files installed on your machine, there some help modules are included by default which covers detailed information of any command available in the Powershell, to get that we need to download or update the files using update-help cmdlet.
Syntax:
Get-Help your “command name”
It has a property -examples to show all the examples available for a specified command that you are looking for help.
Examples
get-help Format-Table
get-help Format-Table -Examples
2. Powershell Get-Member
This is the topmost command or most useful command one must learn, this command gives you the members, properties, and methods of objects and commands.
Syntax
Get-Member
Examples
Examples Get-Process | Get-Member $raja = "I'm learning Powershell" $raja | get-member #The above example commands bring all the objects, properties and methods are available.
3. Powershell Get-Wmiobject
This command gives instances of WMI classes, using this command you can easily work on WMI repository which makes one to manage systems. To understand WMI one needs to go through namespace the root\cimv2, using this get-wmiobject you can query the available classes in a namespace and command we use is get-wmiobject -list. There is an advantage when the machine does not meet the Powershell remoting configuration you can still run the remote job using the WMI.
Syntax
Let’s see a couple of the example commands of class Get-WmiObject -Class Win32
Get-WmiObject -Class Win32_operatingsystem
Output:
SystemDirectory : C:\Windows\system32
Organization : Home
BuildNumber : 177363
RegisteredUser : Raja
SerialNumber : 00329-00000-340003-AA256
Version : 10.0.17763
Get-WmiObject -Class Win32_Service | select name #This lists all the processes available on the computer.
4. Powershell Get-command
This command gives you all Powershell commands that are installed on the computer and it also provides aliases, functions, filers, scripts, and applications.
Examples:
Get-Command -Verb get Get-Command -Module Microsoft.PowerShell.Security
5. Powershell show-command
This command brings a GUI window and shows you how a command works, it’s learning tool and shows all the commands.
Show-Command :: your another powershell command
Examples:
Show-Command Get-Member
6. Powershell Invoke-command
This command is most useful and powerful, we can run commands on remote computers. This allows us to run persistent commands as using New-PSSession, when you want to run the background jobs use AsJob parameter.
Syntax:
This is most powerful command in Powershell, It has a computername, session, scriptblock parameters to work on the remote computer.
Examples:
Invoke-command -computername machine01 -scriptblock {get-service}
The above command brings all the services available on the remote computer name machine01.
Invoke-command -computername machine03 -scriptblock {get-eventlog system}
The above command brings all the system event logs available on the remote computer name machine03.
Invoke-Command -ComputerName machine01, machine02 -ScriptBlock {Get-Process PowerShell} -HideComputerName
Output:
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
——- —— —– —– —– —— — ———–
456 11 35100 70988 100 3.68 1372 PowerShell
677 12 35106 50988 200 7.68 454 PowerShell
7. Powershell Enter-PSSession
This command allows one to connect remote computer and can establish an interactive session, once you are connected remote computer you can run commands, retrieve data and perform actions. This command opens an interactive session within your local powershell window.
Syntax:
# Enter-PSSession [-ComputerName] -HostName <String> Enter-PSSession -computername machine01machine01
[machine01] PS> get-service
[machine01] PS> get-process
8. Powershell Copy-Item
This command used for copying the content from one location to another location.
Copy-Item
Examples
Copying a file to a directory.
Copy-Item "C:\raja\abc\myfirstfile.txt" -Destination "C:\omg"
Copying directory contents to a directory which is already existed
Copy-Item -Path "C:\adobe\*" -Destination "C:\photoshop" -Recurse
9. Powershell converto-html
This command converts the out put any command (MS .NET framework) objects into HTML format and you can use it as file and open in any browser.
Example.
Get-service | ConvertTo-Html | Out-File services.html
10. Powershell remove-Item
This command deletes the files, folders, registry entries, variables, aliases, and functions.
Examples:
Remove-Item -Path C:\temp\java\log.txt -Force Remove-Item HKLM:\Software\snmproot\troops -Recurse
Thank you for reading this article, if you have any questions please let us know.
Thank you for visiting my site, for any scripts in these articles you are testing please make sure you have tested this script in our lower environment before you run in production.
Leave a Reply Cancel reply