Hey guys, i want to programamtically attach a vhd to a VM in hyperv 2,
so far i have got the following powershell code, and it works fine
$HyperVServer ="server" $VMName = "vmname" $VMMS = gwmi -namespace root\virtualization Msvm_VirtualSystemManagementService -computername $HyperVServer $VM = gwmi MSVM_ComputerSystem -filter "ElementName='$VMName'" -namespace "root\virtualization" -computername $HyperVServer $SystemSettingData = $VM.getRelated("Msvm_VirtualSystemSettingData") | where {$_.SettingType -eq 3} $FloppyDrive = $SystemSettingData.getRelated("Msvm_ResourceAllocationSettingData") | where{$_.ResourceType -eq 14} $vfdPath = pathtovfd $FloppyAllocationCapabilities = (gwmi -computername $HyperVServer -namespace root\virtualization Msvm_AllocationCapabilities -filter "ResourceType=21 and ResourceSubType='Microsoft Virtual Floppy Disk'").__Path.Replace('\', '\\') $FloppySettingsData = [wmi](gwmi -computername $HyperVServer -namespace root\virtualization Msvm_SettingsDefineCapabilities -filter "GroupComponent='$FloppyAllocationCapabilities' and ValueRange=0").PartComponent $FloppySettingsData.Connection = $vfdPath $FloppySettingsData.Parent = $FloppyDrive.__Path $result = $VMMS.AddVirtualSystemResources($VM, $FloppySettingsData.GetText(1))
But the problem is that i want these things in c#, currently we are using ManagementScope, Management Object and ManagemenClass to perfom all teh Hyper v WMI operations,
but im unable to crack down the code to attach VFD to a VM,,
Can any one provie me a c# wmi's version of above code.. I know that i can use the above powershell code directly, but we have all other codes written in wmi classes, and also we need to track the status of the result ...
so can any one help me here plz....