• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

TECHDIIP

  • Tech
  • Windows
  • Powershell
  • Scripts
  • News
  • Games

PowerShell Operators

 PowerShell Operators Basically PowerShell comparison operators are declared using the symbol dash (-) followed by a name (eq for equal, gt for greater than, -lt as less than and more.

Comparison operators:

  • 4 -eq  4  # Equal to (=)
  • 3 -ne  5 # Not equal to (!=)
  • 6 -gt  5 # Greater-than (>)
  • 15 -ge  15 # Greater-than or equal to (>=)
  • 3 -lt 10 # Less-than (<)
  • 3 -le  3 # Less-than or equal to (<=)

String comparison operators:

“rajashekar” -like “*shekar”   # This comparison operator used for match using the wildcard character (*)

“rajashekar” -notlike “prava*” # This comparison operator used to check the string does not match using the wildcard (*).

“mylove” -match ‘mylove $’ # This comparison operator used to for matching a string using regular expressions.

“hello” -notmatch  ‘hi’ # This comparison operator used to check as not match a string using regular expressions.

PowerShell  Collection comparison operators:

“raja -contains “raj” #  This comparison operator used for Returning a true when the value (right) is present

“pravaf” -notcontains “123” # This comparison operator used for returning a true when the value (right) is not present

“raja” -in “raja”, “raj” #  This comparison operator returns true when the value (left) is present

“143143” -notin “234”, “345” # This comparison operator  returns true when the value (left) is not present.

PowerShell Arithmetic Operators

  1. +    This operator used for an addition.
  2. –    This operator used for    Subtraction.
  3. #    This operator used for   value.
  4. *    This operator used for multiplication.
  5. /    This operator used for division.
  6. %    This operator used for modulus.

PowerShell  Logical Operators

  1. -and This operator used logical and.
  2. . -or This operator used for logical or.
  3. -xor This operator used for logical exclusive or. 4
  4. -not This operator used for logical not.
  5. ! This operator used for logical not.

PowerShell  Assignment Operators

  1. =    This assignment operator Sets the value of a variable to the specified value
  2. +=  This assignment operator  Increases the value of a variable by the specified value
  3. -=  This assignment operator  Decreases the value of a variable by the specified value.
  4. /=   This assignment operator Divides the value of a variable by the specified value.
  5. %= This assignment operator  Divides the value of a variable by the specified value and then.

1) PowerShell if statement:

If a conditional logic operator used for running the code block if a specified conditional test is true.

Syntax of if–>

if ( condition ) { commands_to_execute }

[ elseif ( condition2 ) { commands_to_execute } ]

[ else {commands_to_execute} ]

Examples:

If ($scripter -eq "I know powershell")
  {

	Write-host " one can write powershell scripts"
	
	}
	
# Two use more than one if statement:

Exalmple 2

# Two use more than one if statement:

If ($scripter -eq "I know powershell")
  {

	Write-host " one can write powershell scripts"
	
	}
Elseif ($scripter -eq " I don't know powershell")
  {
	Write-host "You need to learn powershell"
	
	}
# Negation if statement

$test =  "raja"

If($test -ne "prava")
{
	
Write-host "I found raja"
}

Thank you for reading this article, if you have any questions please let us know.

Thank you for visiting my site, please make sure you have tested this script in our lower environment before you run in production.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Recent Posts

  • How do Zoom Application Testing | Working or Not
  • Powershell script to test website status up or down on a local or remote computers
  • Solved: Server execution failed windows 10 Server 2016 and 2019
  • How to Fix windows 10 version 1903 error 0xc1900223
  • Free Music Making Software List One Can Try Out
  • About Us
  • CONTACT US
  • Disclaimer
  • Privacy Policy

Copyright © 2023 techdiip.com