If you’re like me, sometimes you just feel like counting. Well, in PowerShell you can count easier than ever before! PowerShell gives you ability to not only easily increment, but also run code for each increment because you can pipe! First, let’s take a look at the basic code:
1 2 3 4 5 6 |
PS C:> 1..5 1 2 3 4 5 |
1 2 3 4 |
PS C:> 5..7 5 6 7 |
And why limit yourself to counting up?! You can even decrement those numbers:
1 2 3 4 5 |
PS C:> 6..3 6 5 4 3 |
So, how can you use this? Well, remember the wonderful thing called a pipeline. You can potentially ping an entire subnet with the following command:
1 |
1..254 | % {ping 192.168.1.$_} |
Remember, if that command takes too long, you could consider multithreading it with one of the scripts on this site!