PowerTip: Use PowerShell to Generate Object with Two Property Types


Summary: Use Windows PowerShell to generate an object with two property types.

Hey, Scripting Guy! Question How can I use Windows PowerShell to generate an object with two property types from simply splitting a string?

Hey, Scripting Guy! Answer Use the ConvertFrom-String cmdlet to pipe a string, and then specify the desired property types, for example:

PS C:\>“123 456” | ConvertFrom-String –PropertyType String,Int

 

Comments (4)

  1. Typo says:

    "123 456” | ConvertFrom-String -PropertyNames A,B

  2. Ben says:

    ConvertFrom-String being a PowerShell 5 cmdlet folks.

  3. enema bandit says:

    There’s no such parameter as PropertyType in ConvertFrom-String:

    SYNTAX
    ConvertFrom-String [-Delimiter []] [-PropertyNames []] -InputObject []
    ConvertFrom-String [-IncludeExtent] [-TemplateContent []] [-TemplateFile []] [-UpdateTemplate []] -InputObject

    []
    PSVersion 5.0.10586.0

  4. thomas says:

    You better use -PropertyName instead of -PropertyType to make it work, but the properties type is not right.

Skip to main content