Last year I posted an article and a set of PowerShell functions to make it easier to format values. For some reason, I decided to revisit the functions and ended up revising and extending them. I modified Format-Value so that you can format a number as a currency or a number.
ManageEngine ADManager Plus - Download Free Trial
Exclusive offer on ADManager Plus for US and UK regions. Claim now!
Format-Value help (Image Credit: Jeff Hicks)
The function is assuming you will pipe values to it.
Format-Value examples (Image Credit: Jeff Hicks)
I also wrote a new function called Format-String.
Format-String help (Image Credit: Jeff Hicks)
The nice thing is that you can apply as many or all of the formatting transformations as you want.
Format-String examples (Image Credit: Jeff Hicks)
The Replace option works by taking a hashtable and replacing each matching key with its value.
Using the Replace parameter in Format-String (Image Credit: Jeff Hicks)
One task that comes to mind where Format-String might come in handy is in building passwords.
The function contains the following aliases:
- fp = Format-Percent
- fv = Format-Value
- fs = Format-String
I'm also trying something different, at least for me. Instead of posting the code here, I've started to use GitHub since that seems to be what all the cool kids are doing. You can find the FormatFunctions module at https://github.com/jdhitsolutions/FormatFunctions. This should also make it easier for me to post revisions, address bugs and make it easier for you to take my code and run with it. You're still welcome to post comments here, but use GitHub for anything specific to the PowerShell code.
Enjoy.