{"id":10551,"date":"2006-04-25T12:18:23","date_gmt":"2006-04-25T12:18:23","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2006\/04\/25\/net-types\/"},"modified":"2019-02-18T13:24:54","modified_gmt":"2019-02-18T20:24:54","slug":"net-types","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/net-types\/","title":{"rendered":".NET types"},"content":{"rendered":"<p>In response to&nbsp;the recent Days till Xmas post, applepwc asked the question&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&gt; &nbsp;where can I find more &#8220;.NET types&#8221;?I mean is there a list of &#8220;.NET type&#8221; &nbsp;available in monad? <\/p>\n<p>Excellent question but there are a number of aspects to it so let&#8217;s break it down:<\/p>\n<p>.NET is a developer platform.&nbsp; That platform contains a number of libraries that developers can use to develope their code.&nbsp; Reference information for the classes that ship with the .NET platform are available at <a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/cpref\/html\/frlrfsystemdatetimememberstopic.asp\">http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/cpref\/html\/frlrfsystemdatetimememberstopic.asp<\/a>&nbsp;. <\/p>\n<p>Other developers take that platform and produce their own .NET types and ship them as assemblies (DLLs) or&nbsp;included in their&nbsp;executables.&nbsp;&nbsp;Each team will provide they own documentation for their types.&nbsp; Monad&nbsp;makes this information&nbsp;avilable as part of its SDK.<\/p>\n<p>Then there is the question:&nbsp;which of these types are available to Monad.&nbsp; The answer is that Monad&nbsp;provides access to any public .NET type which is loaded in&nbsp;process.&nbsp;&nbsp;The following&nbsp;sequence tells&nbsp;you what assemblies you have&nbsp;loaded in your current process (appdomain actually but&nbsp;we don&#8217;t need to go there now).<\/p>\n<p><font face=\"Courier New\" color=\"#ff0000\" size=\"2\">MSH&gt; [appdomain]::currentdomain.getassemblies() |ft fullname<\/font><\/p>\n<p><font size=\"2\"><font color=\"#ff0000\"><font face=\"Courier New\">FullName<br \/>&#8212;&#8212;&#8211;<br \/>mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5&#8230;<br \/>System.Management.Automation.ConsoleHost, Version=1.0.490.0, Cul&#8230;<br \/>System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c5&#8230;<br \/>System.Management.Automation, Version=1.0.490.0, Culture=neutral&#8230;<br \/>System.Management.Automation.ConsoleHost.resources, Version=1.0&#8230;.<br \/>System.Configuration.Install, Version=2.0.0.0, Culture=neutral, &#8230;<br \/>System.Management.Automation.Commands.Management, Version=1.0.49&#8230;<br \/>System.Management.Automation.Security, Version=1.0.490.0, Cultur&#8230;<br \/>System.Management.Automation.Commands.Utility, Version=1.0.490.0&#8230;<br \/>System.Management, Version=2.0.0.0, Culture=neutral, PublicKeyTo&#8230;<br \/>System.DirectoryServices, Version=2.0.0.0, Culture=neutral, Publ&#8230;<br \/>System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b7&#8230;<br \/>System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77&#8230;<br \/>System.Management.Automation.resources, Version=1.0.490.0, Cultu&#8230;<br \/>System.Management.Automation.Security.resources, Version=1.0.490&#8230;<br \/>System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKe&#8230;<br \/>System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken&#8230;<br \/>System.Management.Automation.Commands.Utility.resources, Version&#8230;<br \/>System.Management.Automation.Commands.Management.resources, Vers&#8230;<\/font><br \/><\/font><\/font><\/p>\n<p>This call&nbsp;returns an assembly object.&nbsp; This object has a method GetExportedTypes() which gets all the public types (as&nbsp;opposed to private types which you don&#8217;t have access to) for that assemblies.&nbsp;&nbsp;Thus if you wanted to get all the types available in process you would do the following:&nbsp;<\/p>\n<p><font face=\"Courier New\" color=\"#ff0000\" size=\"2\">MSH&gt; [appdomain]::currentdomain.getassemblies() |foreach {$_.getexpo<br \/>rtedtypes()}<\/font><\/p>\n<p><font face=\"Courier New\" color=\"#ff0000\" size=\"2\">IsPublic IsSerial Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BaseType<br \/>&#8212;&#8212;&#8211; &#8212;&#8212;&#8211; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8211;<br \/>True&nbsp;&nbsp;&nbsp;&nbsp; True&nbsp;&nbsp;&nbsp;&nbsp; Object<br \/>True&nbsp;&nbsp;&nbsp;&nbsp; False&nbsp;&nbsp;&nbsp; ICloneable<br \/>True&nbsp;&nbsp;&nbsp;&nbsp; False&nbsp;&nbsp;&nbsp; IEnumerable<br \/>True&nbsp;&nbsp;&nbsp;&nbsp; False&nbsp;&nbsp;&nbsp; ICollection<br \/>True&nbsp;&nbsp;&nbsp;&nbsp; False&nbsp;&nbsp;&nbsp; IList<br \/>True&nbsp;&nbsp;&nbsp;&nbsp; True&nbsp;&nbsp;&nbsp;&nbsp; Array&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Syste&#8230;<br \/>&#8230;.<\/font><\/p>\n<p>I use this quite a bit actually.&nbsp; I create a function Match-Type to find a set of .Net Types:<\/p>\n<p><font face=\"Courier New\" color=\"#ff0000\" size=\"2\">function Match-Type ($Name)<br \/>{&nbsp; [Appdomain]::CurrentDomain.GetAssemblies() |<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach {$_.GetExportedTypes()} |<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; where {$_.FullName -match $Name}<br \/>}<br \/><\/font><\/p>\n<p><font face=\"Courier New\" color=\"#ff0000\" size=\"2\"><br \/>MSH&gt;&nbsp; Match-Type mshhost |ft FullName<\/font><\/p>\n<p><font face=\"Courier New\" color=\"#ff0000\" size=\"2\">FullName<br \/>&#8212;&#8212;&#8211;<br \/>Microsoft.Management.Automation.MshHostMshSnapIn<br \/>System.Management.Automation.Host.MshHost<br \/>System.Management.Automation.Host.MshHostRawUserInterface<br \/>System.Management.Automation.Host.MshHostUserInterface<\/font><\/p>\n<p><font face=\"Courier New\" color=\"#000000\" size=\"2\">This is a good point to take a tangent.&nbsp; In an earlier post, I pointe dou that some .NET types can parse strings and how wonderful that was.&nbsp; You might reasonably ask yourself the question: Which types support the Parse() method.&nbsp; Here is a function that helps address that:<\/font><\/p>\n<p><font face=\"Courier New\" color=\"#ff0000\" size=\"2\">function Match-Method ($Name)<br \/>{&nbsp; [Appdomain]::CurrentDomain.GetAssemblies() |<br \/>&nbsp;&nbsp;&nbsp;&nbsp; foreach {$_.GetExportedTypes()} |<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $Type = $_ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($Type.GetMethods() | where {$_.Name -match $Name}) {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $Type<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>}<br \/>MSH&gt; match-Method Parse<\/font><\/p>\n<p><font face=\"Courier New\" color=\"#ff0000\" size=\"2\">IsPublic IsSerial Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BaseType<br \/>&#8212;&#8212;&#8211; &#8212;&#8212;&#8211; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8211;<br \/>True&nbsp;&nbsp;&nbsp;&nbsp; True&nbsp;&nbsp;&nbsp;&nbsp; Enum&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Syste&#8230;<br \/>True&nbsp;&nbsp;&nbsp;&nbsp; True&nbsp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;&nbsp;&nbsp;&nbsp; Syste&#8230;<br \/>&#8230;<\/font><\/p>\n<p><font face=\"Courier New\" color=\"#ff0000\" size=\"2\"><font color=\"#000000\">The last issue is, how do I load types into my process if they aren&#8217;t already there.&nbsp; Lee Holmes has a great blog entry on that at: <a href=\"http:\/\/www.leeholmes.com\/blog\/HowDoIEasilyLoadAssembliesWhenLoadWithPartialNameHasBeenDeprecated.aspx\">http:\/\/www.leeholmes.com\/blog\/HowDoIEasilyLoadAssembliesWhenLoadWithPartialNameHasBeenDeprecated.aspx<\/a><\/font><\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\">I hope that this was useful.<\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\">Enjoy!<\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\">Jeffrey P. Snover<br \/>Monad Architect<\/font><\/p>\n<p>[<i>Edit: Monad has now been renamed to Windows PowerShell.  This script or discussion may require slight adjustments before it applies directly to newer builds.<\/i>]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In response to&nbsp;the recent Days till Xmas post, applepwc asked the question&nbsp;&nbsp;&nbsp;&nbsp;&gt; &nbsp;where can I find more &#8220;.NET types&#8221;?I mean is there a list of &#8220;.NET type&#8221; &nbsp;available in monad? Excellent question but there are a number of aspects to it so let&#8217;s break it down: .NET is a developer platform.&nbsp; That platform contains a [&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":[],"class_list":["post-10551","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>In response to&nbsp;the recent Days till Xmas post, applepwc asked the question&nbsp;&nbsp;&nbsp;&nbsp;&gt; &nbsp;where can I find more &#8220;.NET types&#8221;?I mean is there a list of &#8220;.NET type&#8221; &nbsp;available in monad? Excellent question but there are a number of aspects to it so let&#8217;s break it down: .NET is a developer platform.&nbsp; That platform contains a [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/10551","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=10551"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/10551\/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=10551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=10551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=10551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}