Created
January 28, 2016 19:15
-
-
Save pvandervelde/7aa6f4d84b2b72a7b60c to your computer and use it in GitHub Desktop.
Powershell changing type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
#> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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