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

前端 未结 4 1867
Happy的楠姐
Happy的楠姐 2021-02-19 06:32

I have a class in C# say for example

public class MyComputer : PSObject
{
    public string UserName
    {
        get { return userName; }
        set { userN         


        
4条回答
  •  情歌与酒
    2021-02-19 07:12

    Here is how it got working.

    public class MyComputer
    {
        public string UserName
        {
            get { return userName; }
            set { userName = value; }
        }
        private string userName;
    
        public string DeviceName
        {
            get { return deviceName; }
            set { deviceName = value; }
        }
    
        public string deviceName;
    }
    
    //PS C:\> $object = New-Object Namespace.ClassName
    PS C:\> $object = New-Object Namespace.MyComputer
    PS C:\> $object.UserName = "Shaj"
    PS C:\> $object.DeviceName = "PowerShell"
    

提交回复
热议问题