-
One of the (many) neat functions of PowerShell is the ability to create aliases for different cmdlets. Aliases allow a user to configure their own names for different cmdlets or scripts, which makes it more straightforward for a user to switch back and forth between different shells: ‘ls’ is a linux bash command that displays directory objects, like the ‘dir’ command. In PowerShell, both ‘ls’ and ‘dir’ are an alias for the cmdlet ‘Get-ChildItem.’
Acess for Scripts to run
- Restricted
- Remote Signed
- AllSigned
- UnRestricted
- ByPass
Set-ExecutionPolicy RemoteSigned
or
Set-ExecutionPolicy unrestricted -Force
RemoteSigned says run any script made locally but not downloaded from internet unless its digitally Signed
invoke-item .
unblock-file filnameWithAddress
- Power Shell Executes in a given scope
- Things defined in scope ends with it
- Scripts runs in their own scope
- Global
- Powershell opens in this scope
- Script
- Scrips runs in their own internal Scope.
- Local
- The current scope. The local scope can be the global scope or any other scope.
- Private
- Numbered Scops
We can create or write in only current scope
help about-scopes
Get-Variable -Scope global
It has
- Hard Coded File Paths
- You will have to create them
Some of the PowerShell Profile e.g,
Even when I am executing my script in VScode or somewhere else It has some Powershell Profile
A basic script file is a text file with .ps1 file extension
- Use # to indicate comments
It will create and Html file with the results and Also will add css to it
use Help Script Name and it will tell you the parameters the script is expecting
Using IF Else
Enumeration
- ForEach-Object
- For Each
- ForEach-Object
- ForEach
In the ForEachObject way we can pipe the result to the end while we can't do the same in forEach 2nd Method
Also, we can Update HashTable
Here we reference the variable using @
- Select
- New
- [pscustomobject]
Piping the Date variable with get-member and then with more can be done with other data types too
$now = get-Date
$now | select *
$now.dayOfWeek
To find all things in Math Class
To invoke methods
We also have Powershell script that orchestrates or runs other powershell commands, functions and scripts
- PowerShell.org
- Http://bit.ly/PSUserGroups