How do I conditionally add a class with Add-Type -TypeDefinition if it isn’t added already?
This technique works well for me: if (-not ([System.Management.Automation.PSTypeName]’MyClass’).Type) { Add-Type -TypeDefinition ‘public class MyClass { }’ } The type name can be enclosed in quotes ‘MyClass’, square brackets [MyClass], or both ‘[MyClass]’ (v3+ only). The type name lookup is not case-sensitive. You must use the full name of the type, unless it is part … Read more