PowerShell – Check if .NET class exists


I have a DLL file that I am importing into the PS session. This creates a new .NET class. At the start of the function I want to test if this class exists, and if it doesn’t import the DLL file.

Currently I am trying to call the class. This works but I think it’s causing problems with the Do {} Until () loop since I have to run the script twice.

my code. note the Do {} Until () loop isn’t working.

I have found the [System.Type]::GetType() Method but when I run it against any kind of string, valid or invalid class, it doesn’t do anything.


In .Net it exists something called Reflexion which allow you deal with everything in your code.

Here I look for the type String, but you can look for your type or better the version of the Assembly, you can even find if one method exists with the correct arguments. Have a look to C# – How to check if namespace, class or method exists in C#?.

@Timmerman comments ; he went with :



PowerShell – Check if .NET class exists by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply