カスタム オブジェクトを使用する PowerShell を使用してスクリプトを作成しています。ただし、注意が必要なのは、このカスタム オブジェクトが別のカスタム オブジェクトをプロパティとして使用していることです。私はC#構文でそれをやろうとしています。
スクリプトを実行しようとすると、次のエラーが発生します。
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;
PowerShellでそれを行う方法はありますか? 1 つのファイルに含まれるクラス コードを次に示します。
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;
}
"@;
私は C# 構文に限定されていないので、すべてのソリューションを歓迎します。