Skip to content

Instantly share code, notes, and snippets.

@pvandervelde
Created January 28, 2016 19:15
Show Gist options
  • Save pvandervelde/7aa6f4d84b2b72a7b60c to your computer and use it in GitHub Desktop.
Save pvandervelde/7aa6f4d84b2b72a7b60c to your computer and use it in GitHub Desktop.
Powershell changing type
function ChangeType
{
[CmdletBinding()]
param (
[string] $input
)
$ErrorActionPreference = "Stop"
$input = $input.Split(',')
Write-Output "Type after splitting: $($input.GetType().FullName)"
}
$arrayAsString = "a,b,c,d"
Write-Output "Type prior to splitting: $($arrayAsString.GetType().FullName)"
ChangeType -input $arrayAsString -Verbose
<#
Result:
Type prior to splitting: System.String
Type after splitting: System.String
#>
$arrayAsString = "a,b,c,d"
Write-Output "Type prior to splitting: $($arrayAsString.GetType().FullName)"
$arrayAsString = $arrayAsString.Split(',')
Write-Output "Type after splitting: $($arrayAsString.GetType().FullName)"
<#
Result:
Type prior to splitting: System.String
Type after splitting: System.String[]
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment