{"id":5551,"date":"2008-09-01T17:53:00","date_gmt":"2008-09-01T17:53:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2008\/09\/01\/get-constructor-fun\/"},"modified":"2019-02-18T13:13:02","modified_gmt":"2019-02-18T20:13:02","slug":"get-constructor-fun","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/get-constructor-fun\/","title":{"rendered":"Get-Constructor Fun"},"content":{"rendered":"<p>Here is a quick and dirty function I wrote after getting PO&#8217;d at having to look up documentation for constructors:<\/p>\n<p>NOTE:&nbsp; Jim Truher thinks long typenames are useful so I added a switch (-FullName) so you could get them if you want them.<\/p>\n<p>function get-Constructor ([type]$type, [Switch]$FullName)<br \/>{<br \/>&nbsp;&nbsp;&nbsp; foreach ($c in $type.GetConstructors())<br \/>&nbsp;&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $type.Name + &#8220;(&#8220;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach ($p in $c.GetParameters())<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($fullName)<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;`t{0} {1},&#8221; -f $p.ParameterType.FullName, $p.Name&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }else<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;`t{0} {1},&#8221; -f $p.ParameterType.Name, $p.Name&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;)&#8221;<br \/>&nbsp;&nbsp;&nbsp; }<br \/>}<\/p>\n<p>PS&gt; get-Constructor System.Windows.Thickness<br \/>Thickness(<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Double uniformLength,<br \/>)<br \/>Thickness(<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Double left,<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Double top,<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Double right,<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Double bottom,<br \/>)<\/p>\n<p>PS&gt; <\/p>\n<p>PS&gt; get-Constructor System.Datetime -FullName<br \/>DateTime(<br \/>&nbsp;System.Int64 ticks,<br \/>)<br \/>DateTime(<br \/>&nbsp;System.Int64 ticks,<br \/>&nbsp;System.DateTimeKind kind,<br \/>)<br \/>DateTime(<br \/>&nbsp;System.Int32 year,<br \/>&nbsp;System.Int32 month,<br \/>&nbsp;System.Int32 day,<br \/>)<br \/>DateTime(<br \/>&nbsp;System.Int32 year,<br \/>&nbsp;System.Int32 month,<br \/>&nbsp;System.Int32 day,<br \/>&nbsp;System.Globalization.Calendar calendar,<br \/>)<br \/>DateTime(<br \/>&nbsp;System.Int32 year,<br \/>&nbsp;System.Int32 month,<br \/>&nbsp;System.Int32 day,<br \/>&nbsp;System.Int32 hour,<br \/>&nbsp;System.Int32 minute,<br \/>&nbsp;System.Int32 second,<br \/>)<br \/>DateTime(<br \/>&nbsp;System.Int32 year,<br \/>&nbsp;System.Int32 month,<br \/>&nbsp;System.Int32 day,<br \/>&nbsp;System.Int32 hour,<br \/>&nbsp;System.Int32 minute,<br \/>&nbsp;System.Int32 second,<br \/>&nbsp;System.DateTimeKind kind,<br \/>)<br \/>DateTime(<br \/>&nbsp;System.Int32 year,<br \/>&nbsp;System.Int32 month,<br \/>&nbsp;System.Int32 day,<br \/>&nbsp;System.Int32 hour,<br \/>&nbsp;System.Int32 minute,<br \/>&nbsp;System.Int32 second,<br \/>&nbsp;System.Globalization.Calendar calendar,<br \/>)<br \/>DateTime(<br \/>&nbsp;System.Int32 year,<br \/>&nbsp;System.Int32 month,<br \/>&nbsp;System.Int32 day,<br \/>&nbsp;System.Int32 hour,<br \/>&nbsp;System.Int32 minute,<br \/>&nbsp;System.Int32 second,<br \/>&nbsp;System.Int32 millisecond,<br \/>)<br \/>DateTime(<br \/>&nbsp;System.Int32 year,<br \/>&nbsp;System.Int32 month,<br \/>&nbsp;System.Int32 day,<br \/>&nbsp;System.Int32 hour,<br \/>&nbsp;System.Int32 minute,<br \/>&nbsp;System.Int32 second,<br \/>&nbsp;System.Int32 millisecond,<br \/>&nbsp;System.DateTimeKind kind,<br \/>)<br \/>DateTime(<br \/>&nbsp;System.Int32 year,<br \/>&nbsp;System.Int32 month,<br \/>&nbsp;System.Int32 day,<br \/>&nbsp;System.Int32 hour,<br \/>&nbsp;System.Int32 minute,<br \/>&nbsp;System.Int32 second,<br \/>&nbsp;System.Int32 millisecond,<br \/>&nbsp;System.Globalization.Calendar calendar,<br \/>)<br \/>DateTime(<br \/>&nbsp;System.Int32 year,<br \/>&nbsp;System.Int32 month,<br \/>&nbsp;System.Int32 day,<br \/>&nbsp;System.Int32 hour,<br \/>&nbsp;System.Int32 minute,<br \/>&nbsp;System.Int32 second,<br \/>&nbsp;System.Int32 millisecond,<br \/>&nbsp;System.Globalization.Calendar calendar,<br \/>&nbsp;System.DateTimeKind kind,<br \/>)<br \/>Enjoy!&nbsp;<\/p>\n<p>Jeffrey Snover [MSFT]<br \/>Windows Management Partner Architect<br \/>Visit the Windows PowerShell Team blog at:&nbsp;&nbsp;&nbsp; <a href=\"http:\/\/blogs.msdn.com\/PowerShell\">http:\/\/blogs.msdn.com\/PowerShell<\/a><br \/>Visit the Windows PowerShell ScriptCenter at:&nbsp; <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\">http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is a quick and dirty function I wrote after getting PO&#8217;d at having to look up documentation for constructors: NOTE:&nbsp; Jim Truher thinks long typenames are useful so I added a switch (-FullName) so you could get them if you want them. function get-Constructor ([type]$type, [Switch]$FullName){&nbsp;&nbsp;&nbsp; foreach ($c in $type.GetConstructors())&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $type.Name + &#8220;(&#8220;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[170],"class_list":["post-5551","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-get-constructor"],"acf":[],"blog_post_summary":"<p>Here is a quick and dirty function I wrote after getting PO&#8217;d at having to look up documentation for constructors: NOTE:&nbsp; Jim Truher thinks long typenames are useful so I added a switch (-FullName) so you could get them if you want them. function get-Constructor ([type]$type, [Switch]$FullName){&nbsp;&nbsp;&nbsp; foreach ($c in $type.GetConstructors())&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $type.Name + &#8220;(&#8220;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/5551","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=5551"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/5551\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=5551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=5551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=5551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}