Get-Constructor by Joel Bennett 21 months ago (modification of post by Joel Bennett view diff)
View followups from Joel Bennett | diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1861"></script>download | new post
Enumerates the constructors of a type with the parameters that they take, so you can figure out what your options are when calling New-Object. Changed it to output something closer to PowerShell syntax
- function Get-Constructor {
- PARAM( [Type]$type )
- $type.GetConstructors() |
- Format-Table @{
- l="$($type.Name) Constructors"
- e={ "New-Object $($type.FullName) $(($_.GetParameters() | ForEach { "[{0}] `${1}" -f $($_.ToString() -split " ") }) -Join ", ")" }
- }
- }
- Set-Alias gctor Get-Constructor
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
PowerShell Code Repository