by
0
6
2,782
3
Top 1% !
Popular
Famous
Easy-to-find
Specified
OpenSource
Popularity: 5823rd place

Published on:

LanguageCSharp
LicenseMIT_X11
OSWindows

CreateVirtualHardDisk: Creates a VHD or VHDX.

<summary>
Creates a VHD or VHDX.
</summary>
<param name="ServerName">The name of the server on which to perform the action.</param>
<param name="VirtualHardDiskPath">The path to the VHD/VHDX to create.</param>
<param name="ParentPath">The path to the parent VHD/VHDX.</param>
<param name="Type">The type for the new VHD/VHDX.</param>
<param name="Format">The format of the new VHD/VHDX.</param>
<param name="FileSize">The size of the new VHD/VHDX.</param>
<param name="BlockSize">The block size of the new VHD/VHDX.</param>
<param name="LogicalSectorSize">The logical sector size of the new VHD/VHDX.</param>
<param name="PhysicalSectorSize">The physical sector size of the new VHD/VHDX.</param>
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/293927/CreateVirtualHardDisk--Creates-a-VHD-or-?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
/// <summary> /// Creates a VHD or VHDX. /// </summary> /// <param name="ServerName">The name of the server on which to perform the action.</param> /// <param name="VirtualHardDiskPath">The path to the VHD/VHDX to create.</param> /// <param name="ParentPath">The path to the parent VHD/VHDX.</param> /// <param name="Type">The type for the new VHD/VHDX.</param> /// <param name="Format">The format of the new VHD/VHDX.</param> /// <param name="FileSize">The size of the new VHD/VHDX.</param> /// <param name="BlockSize">The block size of the new VHD/VHDX.</param> /// <param name="LogicalSectorSize">The logical sector size of the new VHD/VHDX.</param> /// <param name="PhysicalSectorSize">The physical sector size of the new VHD/VHDX.</param> internal static void CreateVirtualHardDisk( string ServerName, string VirtualHardDiskPath, string ParentPath, VirtualHardDiskType Type, VirtualHardDiskFormat Format, Int64 FileSize, Int32 BlockSize, Int32 LogicalSectorSize, Int32 PhysicalSectorSize) { ManagementScope scope = new ManagementScope("\\\\" + ServerName + "\\root\\virtualization\\v2"); VirtualHardDiskSettingData settingData = new VirtualHardDiskSettingData( Type, Format, VirtualHardDiskPath, ParentPath, FileSize, BlockSize, LogicalSectorSize, PhysicalSectorSize); using (ManagementObject imageManagementService = StorageUtilities.GetImageManagementService(scope)) { using (ManagementBaseObject inParams = imageManagementService.GetMethodParameters("CreateVirtualHardDisk")) { inParams["VirtualDiskSettingData"] = settingData.GetVirtualHardDiskSettingDataEmbeddedInstance( ServerName, imageManagementService.Path.Path); using (ManagementBaseObject outParams = imageManagementService.InvokeMethod( "CreateVirtualHardDisk", inParams, null)) { WmiUtilities.ValidateOutput(outParams, scope); } } } }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus