This Video Shows Complete detailed Demo of PowerShell Operators.
This PowerShell Operators Masterclass explains about -
-- PowerShell Arithmetic Operators
-- PowerShell Assignment Operators
-- PowerShell Comparison Operators
-------- PowerShell Equality Operators
-------- PowerShell Matching Operators
-------- PowerShell Containment Operators
---------PowerShell Type Operators
-- PowerShell Logical Operators
-- PowerShell Split & Join Operators
-- PowerShell Unary Operators
-- PowerShell Special Operators
-------- PowerShell Grouping Operators
-------- PowerShell Subexpression Operators
-------- PowerShell Cast Operators
-------- PowerShell comma Operators
-------- PowerShell Index Operators
-------- PowerShell Pipeline Operators
-------- PowerShell Range Operator
**************************************************************************
Code Used in this Masterclass -
Operators####
#### Arithmaetic Operators
+ - * / %
[int]$FirstNumber = Read-Host "Enter 1st Number"
[int]$SecindNumber = Read-Host "Enter 2nd Number"
$FirstNumber + $SecindNumber
$FirstNumber - $SecindNumber
$FirstNumber * $SecindNumber
$FirstNumber % $SecindNumber
"Test" + "Best"
"Test" * 4
Assignment Operators
$FirstNumber += 5
$FirstNumber -= 10
$FirstNumber
Comparision Operators - Return list if collection
Equality Operators
#eq ne gt lt ge le
Behavious changes - Array/List and Single Item
$FirstNumber -eq $SecindNumber
$FirstNumber -lt $SecindNumber
$Numbers = 1..100
$Numbers
$Numbers -lt 50 # Collection Comparision
$Services = Get-Service
($Services).displayname -eq "Windows Update"
$Services -eq "Windows Update"
This operator deals in Strings and Integers
##### Matching Operators - Return List if comparing with Collection
like notlike match notmatch
($Services).displayname -like "Windows*"
"Test" -like "*est"
"Prashant" -match "\d"
#### Containment Operators - It give Only Boolean Value - True/False
$($($Services).displayname) -contains "Windows"
"test","Best" -contains "Test"
$Services.displayname -contains "Windows Update"
$Services.displayname -notcontains "Windows Update"
"Windows Update" -in $Services.displayname
Type Operator
#is or isnot
$FirstNumber -is [int]
$FirstNumber -is [string]
######### Logical Operators
#Or, and. xor, not/!
($FirstNumber -eq $SecindNumber)
Get-Service |Where {$($_.DisplayName -like "Windows*") -or ($_.Status -like "Stopped")} # Atleast one condition - True
Get-Service |Where {($_.DisplayName -like "Windows*") -and ($_.Status -like "Stopped")}
Get-Service |Where {($_.DisplayName -like "Windows*") -xor ($_.Status -like "Stopped")} # Only one condition Should be true
Get-Service |Where {!($_.DisplayName -like "Windows*")}
#### Redirection Operator
#### Join & Split Operator
-Split "This is an Operator"# Space - Default delimeter
"This is an Operator" -split "is" # Delimeter are not included in result
"This - is - an Operator" -split "-"
"This is an Operator" -split " is "
"This is an Operator" -split "(is)"
"This, is -an Operator" -split "[,-]"
"[email protected]" -split "@" # Array as output
$Test = "[email protected]" -split "@"
$test[0]
$test.GetType()
$test = "Tes This POrtion".Split(" ")
#Join Operator
-join ("Sting1","String2")
("Sting1","String2") -join "-"
#### Urary Operator
++ --
$FirstNumber
$FirstNumber++
$FirstNumber--
Special Operator
##### Groups Operators
1 - To Change execution prefernce of Operators
2 - To estimate Dynamic Value
$()
5+5/2
(5+5)/2
#### Call Operator &
$Command = Get-Service
$Command
$CustomCommand = Read-host "What command u want to run"
$CustomCommand
& $CustomCommand # We can't use parameters with command that isstored in Variable and we want to run it using Call Operator"
New-Item .\test_script.ps1 -Value "Get-Service"
gc .\test_script.ps1
$CustomScript = Read-host "What Script u want to run"
$customScript
& $customscript
Cast Operator []
[int]$FirstNumber = Read-Host "Enter 1st Number"
Cast Operator []
Pipeline Operator |
Member Access Operator .
$Services
$Services.displayname
replace
"TestString".Replace("Test","Best")
"TestString" -replace "Test","Best"
Select-String
Help Select-string -Examples
************************************************************************
************************************************************************
Join Me on --
Facebook Group
/ mylearningsonline
Facebook Page
/ mylearningsonline
YouTube Channel
/ mylearningsonline
**************************************************************************
#PowerShell #PowerShellScripting #PowerShellForBeginners #learnPowerShell #PowerShelltraining #PowerShellTutorial #MyLearningsOnline
PowerShell Scripting for Beginners
PowerShell Tutorial for Beginners
PowerShell Full Course
PowerShell Training for Beginners