I'm writing a script using PowerShell which uses a custom object. But the tricky part is that this custom object uses another custom object as a property. I'm trying to do it with C# syntax.
When I'm trying to run the script I'm getting this error:
The type or namespace name 'Disk' could not be found (are you missing a using directive or an assembly reference?)
c:\Users\trumpe\AppData\Local\Temp\orydsmyw.0.cs(1) : public class VirtualMachine{
c:\Users\trumpe\AppData\Local\Temp\orydsmyw.0.cs(2) : >>> public Disk Disks;
c:\Users\trumpe\AppData\Local\Temp\orydsmyw.0.cs(3) : public string IPAddress;
Is there a way to do it at all in PowerShell? Here are my class code in one file:
Add-Type -Language CSharp @"
public class Disk{
public string VirtualMachineDiskID;
public string StorageID;
public string StorageIdentifier;
public string DiskFileName;
public string StorageProfileID;
public int CapacityKB;
public int ControllerKey;
public int DeviceKey;
public int DiskMode;
public int UnitNumber;
}
"@;
Add-Type -Language CSharp @"
public class VirtualMachine{
public Disk Disks; #<=== This part stops working because it cannot find the type Disk
public string IPAddress;
public string Name;
public string OSFullName;
public string PowerState;
public string ResourcePoolID;
public string TenantID;
public string UniqueId;
public string VirtualMachineID;
public int NumCPU;
public int NumNic;
public int StorageCapacityAllocatedMB;
public int RamAllocatedMB;
public bool IsRemoved;
public bool IsTemplate;
}
"@;
I'm not limited to C# syntax so all solutions are welcome.