コード例 #1
0
        private FileInfo ConvertVhd()
        {
            CheckOS();
            WriteWarning("The VHDX file needs to be converted to VHD. During the conversion process, the cmdlet will temporarily create a resized file in the same directory as the provided VHDX file.");

            string                     ConvertedPath = ReturnAvailExtensionName(vhdFileToBeUploaded.FullName, "_converted", ".vhd");
            FileInfo                   vhdFileInfo   = new FileInfo(ConvertedPath);
            ManagementScope            scope         = new ManagementScope(@"\root\virtualization\V2");
            VirtualHardDiskSettingData settingData   = new VirtualHardDiskSettingData(VirtualHardDiskType.DynamicallyExpanding, VirtualHardDiskFormat.Vhd, vhdFileInfo.FullName, null, 0, 0, 0, 0);

            try
            {
                using (ManagementObject imageManagementService =
                           StorageUtilities.GetImageManagementService(scope))
                {
                    WriteVerbose("Converting VHDX file to VHD file.");
                    using (ManagementBaseObject inParams =
                               imageManagementService.GetMethodParameters("ConvertVirtualHardDisk"))
                    {
                        inParams["SourcePath"]             = vhdFileToBeUploaded.FullName;
                        inParams["VirtualDiskSettingData"] =
                            settingData.GetVirtualHardDiskSettingDataEmbeddedInstance(null, imageManagementService.Path.Path);

                        using (ManagementBaseObject outParams = imageManagementService.InvokeMethod(
                                   "ConvertVirtualHardDisk", inParams, null))
                        {
                            ManagementPath   path            = new ManagementPath((string)outParams["Job"]);
                            ManagementObject job             = new ManagementObject(path);
                            string           jobStatus       = (string)job["JobStatus"];
                            ushort           percentComplete = (ushort)job["PercentComplete"];
                            while (jobStatus == "Job is running" && percentComplete < 100)
                            {
                                Program.SyncOutput.ProgressHyperV(percentComplete, "Converting to VHD");
                                Thread.Sleep(1000);
                                job.Get();
                                jobStatus       = (string)job["JobStatus"];
                                percentComplete = (ushort)job["PercentComplete"];
                            }
                            Program.SyncOutput.ProgressHyperV(percentComplete, "Converting to VHD");

                            WmiUtilities.ValidateOutput(outParams, scope);
                        }
                    }
                    temporaryFileCreated = true;
                    WriteVerbose("Converted file: " + ConvertedPath);
                    return(new FileInfo(vhdFileInfo.FullName));
                }
            }
            catch (System.Management.ManagementException ex)
            {
                if (ex.Message == "Invalid namespace ")
                {
                    Exception outputEx = new Exception("Failed to convert VHDX file. Hyper-V Platform is not found.\nFollow this link to enable Hyper-V or convert file manually: https://aka.ms/usingAdd-AzVhd");
                    ThrowTerminatingError(new ErrorRecord(
                                              outputEx,
                                              "Hyper-V is unavailable",
                                              ErrorCategory.InvalidOperation,
                                              null));
                }
                throw ex;
            }
        }
コード例 #2
0
        public void CreatingVirtualHardDisk_ExpectingOneRASDOfTypeVirtualHardDisk()
        {
            var vhdxName = $"{AppDomain.CurrentDomain.BaseDirectory}\\{nameof(CreatingVirtualCDDVD_ExpectingOneRASDOfTypeVirtualCDDVD)}.vhdx";

            using (var viridianUtils = new ViridianUtils())
            {
                viridianUtils.SUT_ComputerSystemMO(
                    ViridianUtils.GetCurrentMethod(),
                    out uint ReturnValue,
                    out ManagementPath Job,
                    out ManagementPath ResultingSystem);

                using (var primordialResourcePoolSCSI = ViridianUtils.GetPrimordialResourcePool("Microsoft:Hyper-V:Synthetic SCSI Controller"))
                    using (var allocationCapabilitiesSCSIController = ViridianUtils.GetAllocationCapabilities(primordialResourcePoolSCSI))
                        using (var resourceAllocationSettingDataSCSIController = ViridianUtils.GetDefaultResourceAllocationSettingData(allocationCapabilitiesSCSIController))
                            using (var computerSystem = new ComputerSystem(ResultingSystem))
                                using (var virtualSystemSettingData = ViridianUtils.GetVirtualSystemSettingDataListThroughSettingsDefineState(computerSystem).First())
                                {
                                    var AffectedConfiguration = virtualSystemSettingData.Path;
                                    var ResourceSettings      = new string[] { resourceAllocationSettingDataSCSIController.LateBoundObject.GetText(TextFormat.WmiDtd20) };
                                    ReturnValue = viridianUtils.VSMS.AddResourceSettings(AffectedConfiguration, ResourceSettings, out Job, out ManagementPath[] ResultingResourceSettings);

                                    using (var scsiController = ViridianUtils.GetResourceAllocationgSettingData(virtualSystemSettingData, 6, "Microsoft:Hyper-V:Synthetic SCSI Controller").First())
                                    {
                                        using (var primordialResourcePoolDiskDrive = ViridianUtils.GetPrimordialResourcePool("Microsoft:Hyper-V:Synthetic Disk Drive"))
                                            using (var allocationCapabilitiesDiskDrive = ViridianUtils.GetAllocationCapabilities(primordialResourcePoolDiskDrive))
                                                using (var resourceAllocationSettingDataDiskDrive = ViridianUtils.GetDefaultResourceAllocationSettingData(allocationCapabilitiesDiskDrive))
                                                {
                                                    resourceAllocationSettingDataDiskDrive.LateBoundObject["Parent"]          = scsiController.Path;
                                                    resourceAllocationSettingDataDiskDrive.LateBoundObject["AddressOnParent"] = 0;

                                                    ResourceSettings = new string[] { resourceAllocationSettingDataDiskDrive.LateBoundObject.GetText(TextFormat.WmiDtd20) };
                                                }
                                        ReturnValue = viridianUtils.VSMS.AddResourceSettings(AffectedConfiguration, ResourceSettings, out Job, out ResultingResourceSettings);

                                        using (var synthethicDiskDrive = ViridianUtils.GetResourceAllocationgSettingData(virtualSystemSettingData, 17, "Microsoft:Hyper-V:Synthetic Disk Drive").First())
                                        {
                                            using (var primordialResourcePoolVirtualHardDisk = ViridianUtils.GetPrimordialResourcePool("Microsoft:Hyper-V:Virtual Hard Disk"))
                                                using (var allocationCapabilitiesVirtualHardDisk = ViridianUtils.GetAllocationCapabilities(primordialResourcePoolVirtualHardDisk))
                                                    using (var resourceAllocationSettingVirtualHardDisk = ViridianUtils.GetDefaultStorageAllocationSettingData(allocationCapabilitiesVirtualHardDisk))
                                                        using (var vhdsd = VirtualHardDiskSettingData.CreateInstance()) // operations on the host
                                                        {
                                                            vhdsd.LateBoundObject["Type"]            = VirtualHardDiskSettingData.TypeValues.Dynamic;
                                                            vhdsd.LateBoundObject["Format"]          = VirtualHardDiskSettingData.FormatValues.VHDX;
                                                            vhdsd.LateBoundObject["Path"]            = vhdxName;
                                                            vhdsd.LateBoundObject["ParentPath"]      = null;
                                                            vhdsd.LateBoundObject["MaxInternalSize"] = 1024 * 1024 * 1024;

                                                            var VirtualDiskSettingData = vhdsd.LateBoundObject.GetText(TextFormat.WmiDtd20);
                                                            viridianUtils.IMS.CreateVirtualHardDisk(VirtualDiskSettingData, out Job);

                                                            ViridianUtils.WaitForStorageJobToEnd(Job);

                                                            var AssignDriveLetter = false;
                                                            var Path     = vhdxName;
                                                            var ReadOnly = false;
                                                            ReturnValue = viridianUtils.IMS.AttachVirtualHardDisk(AssignDriveLetter, Path, ReadOnly, out Job);

                                                            ViridianUtils.WaitForStorageJobToEnd(Job);

                                                            using (var disk =
                                                                       Disk.GetInstances()
                                                                       .Where((d) => string.Compare(d.Location, vhdxName, true, CultureInfo.InvariantCulture) == 0)
                                                                       .ToList()
                                                                       .First())
                                                            {
                                                                ushort PartitionStyle = (ushort)Disk.PartitionStyleValues.GPT;
                                                                disk.Initialize(PartitionStyle, out ManagementBaseObject ExtendedStatus);

                                                                var Alignment = 0U;
                                                                AssignDriveLetter = false;
                                                                var DriveLetter    = '\0';
                                                                var GptType        = "{EBD0A0A2-B9E5-4433-87C0-68B6B72699C7}"; // https://en.wikipedia.org/wiki/GUID_Partition_Table
                                                                var IsActive       = false;
                                                                var IsHidden       = false;
                                                                var MbrType        = (ushort)Partition.MbrTypeValues.Huge;
                                                                var Offset         = 0U;
                                                                var Size           = 0UL;
                                                                var UseMaximumSize = true;

                                                                ReturnValue =
                                                                    disk.CreatePartition(
                                                                        Alignment,
                                                                        AssignDriveLetter,
                                                                        DriveLetter,
                                                                        GptType,
                                                                        IsActive,
                                                                        IsHidden,
                                                                        MbrType,
                                                                        Offset,
                                                                        Size,
                                                                        UseMaximumSize,
                                                                        out ManagementBaseObject CreatePartition,
                                                                        out ExtendedStatus);

                                                                if (ExtendedStatus != null)
                                                                {
                                                                    using (var storageExtendedStatus = new StorageExtendedStatus(ExtendedStatus))
                                                                    {
                                                                        Trace.WriteLine($"{nameof(storageExtendedStatus.CIMStatusCode)}[{storageExtendedStatus.CIMStatusCode}]");
                                                                        Trace.WriteLine($"{nameof(storageExtendedStatus.CIMStatusCodeDescription)}[{storageExtendedStatus.CIMStatusCodeDescription}]");
                                                                        Trace.WriteLine($"{nameof(storageExtendedStatus.ErrorSource)}[{storageExtendedStatus.ErrorSource}]");
                                                                        Trace.WriteLine($"{nameof(storageExtendedStatus.ErrorSourceFormat)}[{storageExtendedStatus.ErrorSourceFormat}]");
                                                                        Trace.WriteLine($"{nameof(storageExtendedStatus.Message)}[{storageExtendedStatus.Message}]");
                                                                        Trace.WriteLine($"{nameof(storageExtendedStatus.MessageArguments)}[{storageExtendedStatus.MessageArguments}]");
                                                                        Trace.WriteLine($"{nameof(storageExtendedStatus.PerceivedSeverity)}[{storageExtendedStatus.PerceivedSeverity}]");
                                                                        Trace.WriteLine($"{nameof(storageExtendedStatus.ProbableCause)}[{storageExtendedStatus.ProbableCause}]");
                                                                        Trace.WriteLine($"{nameof(storageExtendedStatus.ProbableCauseDescription)}[{storageExtendedStatus.ProbableCauseDescription}]");
                                                                        Trace.WriteLine($"{nameof(storageExtendedStatus.RecommendedActions)}[{storageExtendedStatus.RecommendedActions}]");
                                                                    }
                                                                }

                                                                // you could also use "out ManagementBaseObject CreatePartition" from CreatePartition call but this is used as example
                                                                // filter Microsoft Reserved Partition (EBD0A0A2-B9E5-4433-87C0-68B6B72699C7) created when you call Disk.Initialize()
                                                                // => get only Basic data partition (EBD0A0A2-B9E5-4433-87C0-68B6B72699C7)
                                                                using (var partition =
                                                                           DiskToPartition.GetInstances()
                                                                           .Cast <DiskToPartition>()
                                                                           .Where((dtp) =>
                                                                                  string.Compare(new Disk(dtp.Disk).ObjectId, disk.ObjectId, true, CultureInfo.InvariantCulture) == 0 &&
                                                                                  string.Compare(new Partition(dtp.Partition).GptType, "{EBD0A0A2-B9E5-4433-87C0-68B6B72699C7}", true, CultureInfo.InvariantCulture) == 0)
                                                                           .Select((dtp) => new Partition(dtp.Partition))
                                                                           .ToList()
                                                                           .First())
                                                                    using (var volume =
                                                                               PartitionToVolume.GetInstances()
                                                                               .Cast <PartitionToVolume>()
                                                                               .Where((ptv) => string.Compare(new Partition(ptv.Partition).ObjectId, partition.ObjectId, true, CultureInfo.InvariantCulture) == 0)
                                                                               .Select((ptv) => new Volume(ptv.Volume))
                                                                               .ToList()
                                                                               .First())
                                                                    {
                                                                        uint   AllocationUnitSize   = 4096;
                                                                        bool   Compress             = true;
                                                                        bool   DisableHeatGathering = false;
                                                                        string FileSystem           = "NTFS";
                                                                        string FileSystemLabel      = nameof(CreatingVirtualHardDisk_ExpectingOneRASDOfTypeVirtualHardDisk);
                                                                        bool   Force                = true;
                                                                        bool   Full                 = true;
                                                                        bool   IsDAX                = false;
                                                                        bool   RunAsJob             = false;
                                                                        bool   SetIntegrityStreams  = false;
                                                                        bool   ShortFileNameSupport = true;
                                                                        bool   UseLargeFRS          = false;

                                                                        volume.Format(
                                                                            AllocationUnitSize,
                                                                            Compress,
                                                                            DisableHeatGathering,
                                                                            FileSystem,
                                                                            FileSystemLabel,
                                                                            Force,
                                                                            Full,
                                                                            IsDAX,
                                                                            RunAsJob,
                                                                            SetIntegrityStreams,
                                                                            ShortFileNameSupport,
                                                                            UseLargeFRS,
                                                                            out ManagementPath CreatedStorageJob,
                                                                            out ExtendedStatus,
                                                                            out ManagementBaseObject FormattedVolume);
                                                                    }
                                                            }

                                                            ushort CriterionType      = 2;
                                                            var    SelectionCriterion = vhdxName;
                                                            viridianUtils.IMS.FindMountedStorageImageInstance(CriterionType, SelectionCriterion, out ManagementPath Image);

                                                            using (var mountedStorageImage = new MountedStorageImage(Image))
                                                            {
                                                                mountedStorageImage.DetachVirtualHardDisk();
                                                            }

                                                            // end operations on the host

                                                            resourceAllocationSettingVirtualHardDisk.LateBoundObject["Access"]       = 3; // read/write
                                                            resourceAllocationSettingVirtualHardDisk.LateBoundObject["Address"]      = 0;
                                                            resourceAllocationSettingVirtualHardDisk.LateBoundObject["Parent"]       = synthethicDiskDrive.Path.Path;
                                                            resourceAllocationSettingVirtualHardDisk.LateBoundObject["HostResource"] = new[] { vhdxName };

                                                            ResourceSettings = new string[] { resourceAllocationSettingVirtualHardDisk.LateBoundObject.GetText(TextFormat.WmiDtd20) };
                                                        }
                                        }
                                        ReturnValue = viridianUtils.VSMS.AddResourceSettings(AffectedConfiguration, ResourceSettings, out Job, out ResultingResourceSettings);

                                        var virtualHardDiskCollection =
                                            ViridianUtils.GetStorageAllocationSettingDataList(virtualSystemSettingData, 31, "Microsoft:Hyper-V:Virtual Hard Disk")
                                            .Where((sasd) => string.Compare(sasd.Caption, "Hard Disk Image", true, CultureInfo.InvariantCulture) == 0)
                                            .ToList();

                                        Assert.IsNotNull(ResultingSystem);
                                        Assert.AreEqual(0U, ReturnValue);
                                        Assert.AreEqual(1, ResultingResourceSettings.Length);
                                        Assert.AreEqual(1, virtualHardDiskCollection.Count);
                                        File.Delete(vhdxName);
                                    }
                                }
            }
        }
コード例 #3
0
        private void convertDynamicVhdToStatic()
        {
            string                     FixedSizePath = returnAvailExtensionName(this.LocalFilePath.FullName, "_FixedSize", ".vhd");
            FileInfo                   FixedFileInfo = new FileInfo(FixedSizePath);
            ManagementScope            scope         = new ManagementScope(@"\root\virtualization\V2");
            VirtualHardDiskSettingData settingData   = new VirtualHardDiskSettingData(VirtualHardDiskType.FixedSize, VirtualHardDiskFormat.Vhd, FixedFileInfo.FullName, null, 0, 0, 0, 0);

            try
            {
                using (ManagementObject imageManagementService =
                           StorageUtilities.GetImageManagementService(scope))
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("Converting dynamically sized VHD to fixed size VHD.");
                    Console.ResetColor();

                    using (ManagementBaseObject inParams =
                               imageManagementService.GetMethodParameters("ConvertVirtualHardDisk"))
                    {
                        inParams["SourcePath"]             = this.LocalFilePath.FullName;
                        inParams["VirtualDiskSettingData"] =
                            settingData.GetVirtualHardDiskSettingDataEmbeddedInstance(null, imageManagementService.Path.Path);

                        using (ManagementBaseObject outParams = imageManagementService.InvokeMethod(
                                   "ConvertVirtualHardDisk", inParams, null))
                        {
                            ManagementPath   path            = new ManagementPath((string)outParams["Job"]);
                            ManagementObject job             = new ManagementObject(path);
                            string           jobStatus       = (string)job["JobStatus"];
                            ushort           percentComplete = (ushort)job["PercentComplete"];
                            while (jobStatus == "Job is running" && percentComplete < 100)
                            {
                                Program.SyncOutput.ProgressHyperV(percentComplete, "Converting dynamically sized VHD to fixed size VHD");
                                Thread.Sleep(1000);
                                job.Get();
                                jobStatus       = (string)job["JobStatus"];
                                percentComplete = (ushort)job["PercentComplete"];
                            }
                            Program.SyncOutput.ProgressHyperV(percentComplete, "Converting dynamically sized VHD to fixed size VHD");
                            WmiUtilities.ValidateOutput(outParams, scope);
                        }
                        Console.WriteLine("Fixed VHD file: " + FixedSizePath);
                        this.LocalFilePath = FixedFileInfo;
                    }
                }
            }
            catch (System.Management.ManagementException ex)
            {
                if (ex.Message == "Invalid namespace ")
                {
                    Exception outputEx = new Exception("Failed to convert VHD file to fixed size. Hyper-V Platform is not found.\nFollow this link to enabled Hyper-V or convert file manually: https://aka.ms/usingAdd-AzVhd");
                    ThrowTerminatingError(new ErrorRecord(
                                              outputEx,
                                              "Hyper-V is unavailable",
                                              ErrorCategory.InvalidOperation,
                                              null));
                }
                else
                {
                    throw ex;
                }
            }
        }
コード例 #4
0
        public void AutomatedOSInstallationWindows10Version1903x64_ExpectingFileThatMarksTheJobAsFinishedInVM()
        {
            var vhdxName        = $"{AppDomain.CurrentDomain.BaseDirectory}\\{ViridianUtils.GetCurrentMethod()}.vhdx";
            var isoName         = $"{AppDomain.CurrentDomain.BaseDirectory}\\{ViridianUtils.GetCurrentMethod()}.iso";
            var uri             = "https://filetransfer.io/data-package/AwILWW3y?do=download";
            var expectedSHA256  = "4bc7170baa665f4d92ba379843b47e83b384313fb6edf3fae09bc9dd42cd8426".ToUpperInvariant();
            var fileHashMatches = false;

            var computedSHA256 = ViridianUtils.GetFileSHA256HexUpperCase(isoName);

            Trace.WriteLine($"Expected SHA256 [{expectedSHA256}] Computed SHA256 [{computedSHA256}]");

            fileHashMatches = computedSHA256 == expectedSHA256;

            if (fileHashMatches == false)
            {
                ViridianUtils.DownloadFile(uri, isoName);

                computedSHA256 = ViridianUtils.GetFileSHA256HexUpperCase(isoName);

                Trace.WriteLine($"Expected SHA256 [{expectedSHA256}] Computed SHA256 [{computedSHA256}]");

                fileHashMatches = computedSHA256 == expectedSHA256;

                if (fileHashMatches == false)
                {
                    throw new Exception($"Invalid SHA256 for file [{isoName}]!");
                }
            }

            using (var viridianUtils = new ViridianUtils())
            {
                viridianUtils.SUT_ComputerSystemMO(
                    ViridianUtils.GetCurrentMethod(),
                    out uint ReturnValue,
                    out ManagementPath Job,
                    out ManagementPath ResultingSystem);

                var primordialResourcePoolSCSI                  = ViridianUtils.GetPrimordialResourcePool("Microsoft:Hyper-V:Synthetic SCSI Controller");
                var allocationCapabilitiesSCSIController        = ViridianUtils.GetAllocationCapabilities(primordialResourcePoolSCSI);
                var resourceAllocationSettingDataSCSIController = ViridianUtils.GetDefaultResourceAllocationSettingData(allocationCapabilitiesSCSIController);

                using (var computerSystem = new ComputerSystem(ResultingSystem))
                {
                    using (var virtualSystemSettingData = ViridianUtils.GetVirtualSystemSettingDataListThroughSettingsDefineState(computerSystem).First())
                    {
                        var AffectedConfiguration = virtualSystemSettingData.Path;
                        var ResourceSettings      = new string[] { resourceAllocationSettingDataSCSIController.LateBoundObject.GetText(TextFormat.WmiDtd20) };
                        ReturnValue = viridianUtils.VSMS.AddResourceSettings(AffectedConfiguration, ResourceSettings, out Job, out ManagementPath[] ResultingResourceSettings);

                        using (var scsiController = ViridianUtils.GetResourceAllocationgSettingData(virtualSystemSettingData, 6, "Microsoft:Hyper-V:Synthetic SCSI Controller").First())
                        {
                            using (var primordialResourcePoolDVDDrive = ViridianUtils.GetPrimordialResourcePool("Microsoft:Hyper-V:Synthetic DVD Drive"))
                                using (var allocationCapabilitiesDVDDrive = ViridianUtils.GetAllocationCapabilities(primordialResourcePoolDVDDrive))
                                    using (var resourceAllocationSettingDataDVDDrive = ViridianUtils.GetDefaultResourceAllocationSettingData(allocationCapabilitiesDVDDrive))
                                    {
                                        resourceAllocationSettingDataDVDDrive.LateBoundObject["Parent"]          = scsiController.Path;
                                        resourceAllocationSettingDataDVDDrive.LateBoundObject["AddressOnParent"] = 0;

                                        ResourceSettings = new string[] { resourceAllocationSettingDataDVDDrive.LateBoundObject.GetText(TextFormat.WmiDtd20) };
                                    }
                            ReturnValue = viridianUtils.VSMS.AddResourceSettings(AffectedConfiguration, ResourceSettings, out Job, out ResultingResourceSettings);

                            using (var synthethicDVD = ViridianUtils.GetResourceAllocationgSettingData(virtualSystemSettingData, 16, "Microsoft:Hyper-V:Synthetic DVD Drive").First())
                                using (var primordialResourcePoolVirtualCDDVD = ViridianUtils.GetPrimordialResourcePool("Microsoft:Hyper-V:Virtual CD/DVD Disk"))
                                    using (var allocationCapabilitiesVirtualCDDVD = ViridianUtils.GetAllocationCapabilities(primordialResourcePoolVirtualCDDVD))
                                        using (var resourceAllocationSettingVirtualCDDVD = ViridianUtils.GetDefaultStorageAllocationSettingData(allocationCapabilitiesVirtualCDDVD))
                                        {
                                            resourceAllocationSettingVirtualCDDVD.LateBoundObject["Address"]      = 0;
                                            resourceAllocationSettingVirtualCDDVD.LateBoundObject["Parent"]       = synthethicDVD.Path;
                                            resourceAllocationSettingVirtualCDDVD.LateBoundObject["HostResource"] = new[] { isoName };

                                            ResourceSettings = new string[] { resourceAllocationSettingVirtualCDDVD.LateBoundObject.GetText(TextFormat.WmiDtd20) };
                                        }
                            ReturnValue = viridianUtils.VSMS.AddResourceSettings(AffectedConfiguration, ResourceSettings, out Job, out ResultingResourceSettings);

                            using (var primordialResourcePoolDiskDrive = ViridianUtils.GetPrimordialResourcePool("Microsoft:Hyper-V:Synthetic Disk Drive"))
                                using (var allocationCapabilitiesDiskDrive = ViridianUtils.GetAllocationCapabilities(primordialResourcePoolDiskDrive))
                                    using (var resourceAllocationSettingDataDiskDrive = ViridianUtils.GetDefaultResourceAllocationSettingData(allocationCapabilitiesDiskDrive))
                                    {
                                        resourceAllocationSettingDataDiskDrive.LateBoundObject["Parent"]          = scsiController.Path;
                                        resourceAllocationSettingDataDiskDrive.LateBoundObject["AddressOnParent"] = 1;

                                        ResourceSettings = new string[] { resourceAllocationSettingDataDiskDrive.LateBoundObject.GetText(TextFormat.WmiDtd20) };
                                    }
                        }
                        ReturnValue = viridianUtils.VSMS.AddResourceSettings(AffectedConfiguration, ResourceSettings, out Job, out ResultingResourceSettings);

                        using (var synthethicDiskDrive = ViridianUtils.GetResourceAllocationgSettingData(virtualSystemSettingData, 17, "Microsoft:Hyper-V:Synthetic Disk Drive").First())
                            using (var primordialResourcePoolVirtualHardDisk = ViridianUtils.GetPrimordialResourcePool("Microsoft:Hyper-V:Virtual Hard Disk"))
                                using (var allocationCapabilitiesVirtualHardDisk = ViridianUtils.GetAllocationCapabilities(primordialResourcePoolVirtualHardDisk))
                                    using (var resourceAllocationSettingVirtualHardDisk = ViridianUtils.GetDefaultStorageAllocationSettingData(allocationCapabilitiesVirtualHardDisk))
                                    {
                                        using (var vhdsd = VirtualHardDiskSettingData.CreateInstance())
                                        {
                                            vhdsd.LateBoundObject["Type"]            = VirtualHardDiskSettingData.TypeValues.Dynamic;
                                            vhdsd.LateBoundObject["Format"]          = VirtualHardDiskSettingData.FormatValues.VHDX;
                                            vhdsd.LateBoundObject["Path"]            = vhdxName;
                                            vhdsd.LateBoundObject["ParentPath"]      = null;
                                            vhdsd.LateBoundObject["MaxInternalSize"] = 1024UL * 1024 * 1024 * 100;

                                            var VirtualDiskSettingData = vhdsd.LateBoundObject.GetText(TextFormat.WmiDtd20);
                                            viridianUtils.IMS.CreateVirtualHardDisk(VirtualDiskSettingData, out Job);

                                            ViridianUtils.WaitForStorageJobToEnd(Job);
                                        }

                                        resourceAllocationSettingVirtualHardDisk.LateBoundObject["Access"]       = 3; // read/write
                                        resourceAllocationSettingVirtualHardDisk.LateBoundObject["Address"]      = 0;
                                        resourceAllocationSettingVirtualHardDisk.LateBoundObject["Parent"]       = synthethicDiskDrive.Path.Path;
                                        resourceAllocationSettingVirtualHardDisk.LateBoundObject["HostResource"] = new[] { vhdxName };

                                        ResourceSettings = new string[] { resourceAllocationSettingVirtualHardDisk.LateBoundObject.GetText(TextFormat.WmiDtd20) };
                                    }
                        ReturnValue = viridianUtils.VSMS.AddResourceSettings(AffectedConfiguration, ResourceSettings, out Job, out ResultingResourceSettings);

                        ReturnValue = computerSystem.RequestStateChange(2, null, out Job);

                        ViridianUtils.WaitForConcreteJobToEnd(Job);

                        using (var guestServiceInterfaceComponentSettingData = ViridianUtils.GetGuestServiceInterfaceComponentSettingData(virtualSystemSettingData))
                        {
                            guestServiceInterfaceComponentSettingData.LateBoundObject["EnabledState"] = GuestServiceInterfaceComponentSettingData.EnabledStateValues.Enabled;

                            var GuestServiceSettings = new string[1] {
                                guestServiceInterfaceComponentSettingData.LateBoundObject.GetText(TextFormat.WmiDtd20)
                            };
                            ReturnValue = viridianUtils.VSMS.ModifyGuestServiceSettings(GuestServiceSettings, out Job, out ManagementPath[] ResultingGuestServices);
                        }

                        ViridianUtils.WaitForConcreteJobToEnd(Job);

                        using (var guestServiceInterfaceComponent = ViridianUtils.GetGuestServiceInterfaceComponent(computerSystem))
                            using (var guestFileService = ViridianUtils.GetGuestFileService(guestServiceInterfaceComponent))
                                using (var copyFileToGuestSettingData = CopyFileToGuestSettingData.CreateInstance())
                                {
                                    copyFileToGuestSettingData.DestinationPath   = @"C:\finished";
                                    copyFileToGuestSettingData.OverwriteExisting = false;
                                    copyFileToGuestSettingData.SourcePath        = @"C:\copyme";
                                    copyFileToGuestSettingData.CreateFullPath    = true;

                                    // this check might still be a bit too early but.. heh
                                    // right now I do not know a decent way to check if account set up finished
                                    var retries       = 20;
                                    var retryWaitTime = 1; // minutes
                                    var lastErrorcode = 0;
                                    var fileExists    = false;

                                    for (int i = 0; i < retries; i++)
                                    {
                                        var CopyFileToGuestSettings = new string[1] {
                                            copyFileToGuestSettingData.LateBoundObject.GetText(TextFormat.CimDtd20)
                                        };
                                        ReturnValue = guestFileService.CopyFilesToGuest(CopyFileToGuestSettings, out Job);

                                        using (var copyFileToGuestJob = new CopyFileToGuestJob(Job))
                                        {
                                            ViridianUtils.WaitForCopyFileToGuestJobToEnd(Job);

                                            copyFileToGuestJob.LateBoundObject.Properties.Cast <PropertyData>().ToList().ForEach((p) => Trace.WriteLine($"{p.Name} [{p.Value?.ToString()}]"));

                                            lastErrorcode = copyFileToGuestJob.ErrorCode;
                                            fileExists    = copyFileToGuestJob.ErrorDescription.Contains("The file exists. (0x80070050)");

                                            if (fileExists)
                                            {
                                                break;
                                            }

                                            Thread.Sleep(new TimeSpan(0, retryWaitTime, 0));
                                        }
                                    }

                                    Assert.AreEqual(32768, lastErrorcode);
                                    Assert.IsTrue(fileExists);
                                }

                        ReturnValue = computerSystem.RequestStateChange(3, null, out Job);

                        ViridianUtils.WaitForConcreteJobToEnd(Job);

                        viridianUtils.Dispose(); // force destroy system

                        var vhdxMO = ResultingResourceSettings[0];

                        var jobsAffectingVHDX =
                            AffectedJobElement.GetInstances()
                            .Where((aje) => string.Compare(aje.AffectedElement.Path, vhdxMO.Path, true, CultureInfo.InvariantCulture) == 0)
                            .Select((aje) => aje.AffectingElement)
                            .ToList();

                        jobsAffectingVHDX.ForEach((job) => ViridianUtils.WaitForConcreteJobToEnd(Job));

                        File.Delete(vhdxName);
                    }
                }

                File.Delete(isoName);
            }
        }