I often find myself in situations when I want to PSRemote multiple servers with server names in such a series that has same prefix server names and suffixed by a 2 digit number like-
sameprefix05 sameprefix06 sameprefix07 sameprefix08 sameprefix09 sameprefix10 sameprefix11 sameprefix12 sameprefix13 sameprefix14 sameprefix15
and to avoid saving the server names in a file and directly PSRemote them, I do something like in the below screenshot to generate the series
This is smart, but that doesn’t work because the single digit numbers don’t comply the server name nomenclature in the above example, which should be like 05 instead of 5
So I was wondering, there has to be a better way.
To our rescue PowerShell provides -f format operator ( PowerShell Format Operator ) which could be used to make this work.
This small trick helps me a lot in day-to-day operations and hopefully, will help you as well. You can find more such PowerShell Tips here.
Please do follow me on twitter for more Interesting PowerShell material and don’t forget to Show-off cool trick to your colleagues, thanks for reading. Cheers! 😉
Prateek Singh
Related posts
Categories
Author of Books
Awards
Open Sourced Projects
Author at
Blog Roll
Mike F RobbinsDamien Van Robaeys
Stéphane van Gulick
Kevin Marquette
Adam Bertram
Stephanos Constantinou
Francois-Xavier Cat
Ravikanth Chaganti
Roman Levchenko
Blog Stats
- 1,132,499 People Reached