Powershell beginner commands
Important points before you start knowing and practice these Powershell commands.
- Powershell commands are case-insensitive but filenames are case-sensitive
- You will remember these commands only when you type not copy the commands.
- Powershell file extension: “.ps1”
- Commenting any line in PowerShell is with #(pound) symbol.
- Variables defined using $(dollar) symbol along with the name of your variable. Ex: $name
- Strings we can write either using the ‘ single coded string ’ or “ double coded string“
- In general, Computer does not understand our high-level commands for many programming languages uses compilers and interpreters to compile high level to a computer that understands the format. In Powershell, have a similar but first it stores/checks in AST (Abstract Syntax Tree) — Stores in memory and then runs. Before the computer runs first Powershell checks here and if everything is good then the computer runs.
- An important command is Get-Help -Name “<Nameofyourcommand”> -Full => You will know detailed information about the command. Ex: Write-Output
Command 1: To create a new file
New-Item <fileName>.ps1
Command 2: To add script inside the file
code <fileName>.ps1
Note: As in this example it opens VS Code
Statement: To write output in the console window
Write-Output “<String what you want>”
Refer to the above screenshot.
Command 3: To run the Powershell file
.\<FileName>.ps1
To comment on any text in PowerShell file
# Write-Output “Hello”
Statement: Read the input from the user
$name = Read-Host -Prompt “Please enter your name”
Write-Output “Hello $name! “
To know detailed information about any cmdlet
Get-Help -Name “Write-Output” -Full
It’s your time to start Powershell. I will come up with few more important commands and keep practising.
-Happy Reading :)