The Convert-String command may be used to simplify some string conversion operations. The conversion is performed based on an example that must be supplied. For example, Convert-String can generate account names from a list of users:
'Michael Caine', 'Benny Hill', 'Raf Vallone' | Convert-String -Example 'Michael Caine=MCaine'
The example parameter uses the generalized syntax:
<Before>=<After>
This example text does not have to be one of the set being converted, for example, the following will work:
'Michael Caine', 'Benny Hill', 'Raf Vallone' | Convert-String -Example 'First Second=FSecond'
The following alternate syntax is also supported:
'Michael Caine', 'Benny Hill', 'Raf Vallone' | Convert-String -Example @{ Before = 'First Second' After = 'FSecond' }
The Convert-String command is not without its limitations. After may only include strings, or partial strings, from Before along with a sub-set of punctuation characters. Characters that are not permitted in After include @, $, ~, `, and !. Because of these limitations, Convert-String cannot, for example, build an email address for each user in the list in a single step.