Skip to content

Instantly share code, notes, and snippets.

@ArtisanByteCrafter
Last active June 9, 2020 05:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArtisanByteCrafter/9c1a50771dbe715d4411625dd271e94b to your computer and use it in GitHub Desktop.
Save ArtisanByteCrafter/9c1a50771dbe715d4411625dd271e94b to your computer and use it in GitHub Desktop.

Updated Display Name string builder to more flexible format. {0} and {1} are positional indicators.

-f $FirstName,$LastName defines an array of objects to pass into the string in whatever positions desired.

Example Usage:

PS> $FirstName = 'Nate'
PS> $LastName = 'Webb'
PS> "{0} {1}" -f $FirsName,$LastName
Nate Webb
PS>

If you wanted the Display Name to be reversed ('Webb Nate') simply reverse the positional indicators {1} and {0} like so:

PS> $FirstName = 'Nate'
PS> $LastName = 'Webb'
PS> "{1} {0}" -f $FirsName,$LastName
Webb Nate
PS>

You can also mix and match, or duplicate:

PS> $FirstName = 'Austin'
PS> $MiddleName = 'Danger'
PS> $LastName = 'Powers'
PS> "{0}...{1} {2}. (awkward silence)...'Yeah Baby!' `n`n -{0} {2}" -f $FirstName,$MiddleName,$LastName
Austin...Danger Powers. (awkward silence)...'Yeah Baby!'

-Austin Powers
PS>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment