Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading custom static classes in PowerShell

Tags:

powershell

I've searched and searched for info on how to load a custom static class in PowerShell but up to now no avail. I'm googled out. I've seen enougth info and samples on how to load custom classes that need to be instantiated or how to load .Net framework classes but not exactly what I'm looking for.

I'm trying to use a custom dll, written in C# with following structure:

namespace Custom.NameSpace
{
   public static class AppCfgHelper
   {
      public static XmlNode SomeXmlNodeFunction( XmlNode xmlRoot )
      {
       ...
       }
   }
}

Can anybody help please?

like image 937
VagaBond Avatar asked May 08 '26 23:05

VagaBond


1 Answers

There are two steps. First load the assembly containing your static class e.g.:

Add-Type -Path <path-to-dll>

Then use invoke the static method using PowerShell's static method syntax [typename]::membername e.g.:

$returnedNode = [Custom.NameSpace.AppCfgHelper]::SomeXmlNodeFunction($rootNode)
like image 88
Keith Hill Avatar answered May 11 '26 15:05

Keith Hill