internal/functions/Get-ShortType.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Function Get-ShortType {
  <#
    .SYNOPSIS
      Strip a type of it's brackets
    .DESCRIPTION
      Strip a PowerShell type of the brackets, turning [string] and [string[]] into string and string[]
      This makes inserting the type back into PowerShell a little easier.
    .PARAMETER PropertyType
      THe property type of a DSC resource property
    .EXAMPLE
      Get-ShortType -PropertyType $DscResource.Properties[0].PropertyType
 
      This will return a string representing the property type stripped of its outer brackets
  #>

  [cmdletbinding()]
  [OutputType([String])]
  Param (
    [string]$PropertyType
  )
  if ($PropertyType.StartsWith('[') -and $PropertyType.EndsWith(']')) {
    $ShortType = $PropertyType.Substring(1, $PropertyType.Length - 2)
  }
  else {
    $ShortType = $PropertyType
  }
  $ShortType
}