NAME
Convert-String
SYNOPSIS
Formats a string to match examples.SYNTAX
Convert-String [-Example
] -InputObject [ ] DESCRIPTION
The Convert-String cmdlet formats a string to match the format of examples.
PARAMETERS
-Example
Specifies a list of examples of the target format. Specify pairs separated by the equal (=) sign, with the source pattern on the left and the target pattern on the right, as in the following example: `Patti Fuller = Fuller, P.` Alternatively, specify a list of hash tables that contain Before and After properties. Required? false Position? named Default value None Accept pipeline input? False Accept wildcard characters? false-InputObject
Specifies a string to format. Required? true Position? named Default value None Accept pipeline input? True (ByValue) Accept wildcard characters? falseThis cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable, and OutVariable. For more information, see about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216). INPUTS
String You can pipe strings to this cmdlet.OUTPUTS
String This cmdlet returns a string.NOTES
Example 1: Convert format of a string
PS C:\>$Names = "Evan Narvaez","David Chew","Elisa Daugherty"
Convert-String -InputObject $Names -Example "Patti Fuller = Fuller, P."
Narvaez, E. Chew, D. Daugherty, E.The first command creates an array named $Names that contains first and last names.
The second command formats the names in $Names according to the example. It puts the surname first in the output,
followed by an initial.Example 2: Format process information
PS C:\>$Processes = Get-Process -Name "svchost" | Select-Object -Property processname, id | ConvertTo-Csv
-NoTypeInformation
PS C:\> $Processes | Convert-String -Example '"svchost", "219"=219, s.'
716, s. 892, s. 908, s. 1004, s. ...The first command gets processes named svchost by using the Get-Process cmdlet. The command passes them to the
Select-Object cmdlet, which selects the process name and process ID. The command converts the output to comma
separated values without type information by using the ConvertTo-Csv cmdlet. The command stores the results in the
$Processes variable. $Processes now contains SVCHOST and PID.
The second command specifies an example that changes the order of the items and abbreviates svchost. The commandcoverts each string in $Processes .
RELATED LINKS
Online Version: http://go.microsoft.com/fwlink/?LinkId=821756ConvertFrom-String
ConvertTo-Csv
Out-String
Select-Object