How to use New-Object of a class present in a C# DLL using PowerShell

Viewed 35234

I have a class in C# say for example

public class MyComputer : PSObject
{
    public string UserName
    {
        get { return userName; }
        set { userName = value; }
    }
    private string userName;

    public string DeviceName
    {
        get { return deviceName; }
        set { deviceName = value; }
    }
    public string deviceName;
}

which is derived from PSObject. I am loading the DLL having this code in powershell using import-module. Then I tried to create a new object of the MyComputer class in PowerShell.

PS C:> $MyCompObj = New-Object MyComputer

but it throws an error saying make sure assembly containing this type is loaded. Note: I am able to call Cmdlets successfully which is present in the DLL.

I am not sure is this the right way to go ahead on creating a new object. Please correct to me make this work.

4 Answers
Related