Converting VBScript's Mod Operator

Windows PowerShell

Definition: Divides two numbers and returns only the remainder.


The Mod operator is a bit of an odd duck (although it does have its uses): it divides two numbers and then returns the remainder. In Windows PowerShell you can achieve the same effect by using the % operator. For example, this command divides 28 by 5, then stores the remainder in the variable $a:

$a = 28 % 5

When you run this command and then echo back the value of $a you should get the following:


Return to the VBScript to Windows PowerShell home page