What Does Percent(%) Mean in PowerShell

Using Percent (%) in Different Contexts

Typically the % character is for mod functionality. But in PowerShell, it’s an alias for ForEach-Objectand can be also used as Modulus Operator and an Assignment Operator (%=). Let’s learn each of them below.

Use Percent(%) as an alias of the ForEach-Object cmdlet in PowerShell

We can use % sign instead of ForEach-Object cmdlet as % is alias for ForEach-Object cmdlet.

The above command will list all of the aliases for the cmdlet ForEach-Object. In PowerShell, the alias is a short and alternate name for a function, cmdlet, or script. For example, the ForEach-Object cmdlet is used to perform a specific operation on every item in a collection of input objects, and it is an alias for % and foreach.

Let’s see with the help of example:

This example takes an array of three integers and divides each one of them by 10.

As we can see, we replaced ForEach-Object with % and it worked in same way.

Use percent (%) as the Modulus Operator in PowerShell

Here, the % is a modulus operator when applied to an equation; we ran the above command to check this.

Use percent(%) as an assignment operator (%=) in PowerShell

That’s all about what does percent mean in PowerShell.

Was this post helpful?

Leave a Reply

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