@ -187,49 +187,51 @@ Hyper-V\Set-VMFloppyDiskDrive -VMName $vmName -Path $null
return err
}
func CreateVirtualMachine ( vmName string , path string , harddrivePath string , vhdRoot string , ram int64 , diskSize int64 , switchName string , generation uint , diffDisks bool ) error {
func CreateVirtualMachine ( vmName string , path string , harddrivePath string , vhdRoot string , ram int64 , diskSize int64 , diskBlockSize int64 , switchName string , generation uint , diffDisks bool ) error {
if generation == 2 {
var script = `
param ( [ string ] $ vmName , [ string ] $ path , [ string ] $ harddrivePath , [ string ] $ vhdRoot , [ long ] $ memoryStartupBytes , [ long ] $ newVHDSizeBytes , [ string ] $ switchName , [ int ] $ generation , [ string ] $ diffDisks )
param ( [ string ] $ vmName , [ string ] $ path , [ string ] $ harddrivePath , [ string ] $ vhdRoot , [ long ] $ memoryStartupBytes , [ long ] $ newVHDSizeBytes , [ long ] $ vhdBlockSizeBytes , [ string ] $ switchName , [ int ] $ generation , [ string ] $ diffDisks )
$ vhdx = $ vmName + ' . vhdx '
$ vhdPath = Join - Path - Path $ vhdRoot - ChildPath $ vhdx
if ( $ harddrivePath ) {
if ( $ diffDisks - eq "true" ) {
New - VHD - Path $ vhdPath - ParentPath $ harddrivePath - Differencing
New - VHD - Path $ vhdPath - ParentPath $ harddrivePath - Differencing - BlockSizeBytes $ vhdBlockSizeBytes
} else {
Copy - Item - Path $ harddrivePath - Destination $ vhdPath
}
Hyper - V \ New - VM - Name $ vmName - Path $ path - MemoryStartupBytes $ memoryStartupBytes - VHDPath $ vhdPath - SwitchName $ switchName - Generation $ generation
} else {
Hyper - V \ New - VM - Name $ vmName - Path $ path - MemoryStartupBytes $ memoryStartupBytes - NewVHDPath $ vhdPath - NewVHDSizeBytes $ newVHDSizeBytes - SwitchName $ switchName - Generation $ generation
Hyper - V \ New - VHD - Path $ vhdPath - SizeBytes $ newVHDSizeBytes - BlockSizeBytes $ vhdBlockSizeBytes
Hyper - V \ New - VM - Name $ vmName - Path $ path - MemoryStartupBytes $ memoryStartupBytes - VHDPath $ vhdPath - SwitchName $ switchName - Generation $ generation
}
`
var ps powershell . PowerShellCmd
if err := ps . Run ( script , vmName , path , harddrivePath , vhdRoot , strconv . FormatInt ( ram , 10 ) , strconv . FormatInt ( diskSize , 10 ) , s witchName, strconv . FormatInt ( int64 ( generation ) , 10 ) , strconv . FormatBool ( diffDisks ) ) ; err != nil {
if err := ps . Run ( script , vmName , path , harddrivePath , vhdRoot , strconv . FormatInt ( ram , 10 ) , strconv . FormatInt ( diskSize , 10 ) , s trconv. FormatInt ( diskBlockSize , 10 ) , s witchName, strconv . FormatInt ( int64 ( generation ) , 10 ) , strconv . FormatBool ( diffDisks ) ) ; err != nil {
return err
}
return DisableAutomaticCheckpoints ( vmName )
} else {
var script = `
param ( [ string ] $ vmName , [ string ] $ path , [ string ] $ harddrivePath , [ string ] $ vhdRoot , [ long ] $ memoryStartupBytes , [ long ] $ newVHDSizeBytes , [ string ] $ switchName , [ string ] $ diffDisks )
param ( [ string ] $ vmName , [ string ] $ path , [ string ] $ harddrivePath , [ string ] $ vhdRoot , [ long ] $ memoryStartupBytes , [ long ] $ newVHDSizeBytes , [ long ] $ vhdBlockSizeBytes , [ string ] $ switchName , [ string ] $ diffDisks )
$ vhdx = $ vmName + ' . vhdx '
$ vhdPath = Join - Path - Path $ vhdRoot - ChildPath $ vhdx
if ( $ harddrivePath ) {
if ( $ diffDisks - eq "true" ) {
New - VHD - Path $ vhdPath - ParentPath $ harddrivePath - Differencing
New - VHD - Path $ vhdPath - ParentPath $ harddrivePath - Differencing - BlockSizeBytes $ vhdBlockSizeBytes
}
else {
Copy - Item - Path $ harddrivePath - Destination $ vhdPath
}
Hyper - V \ New - VM - Name $ vmName - Path $ path - MemoryStartupBytes $ memoryStartupBytes - VHDPath $ vhdPath - SwitchName $ switchName
} else {
Hyper - V \ New - VM - Name $ vmName - Path $ path - MemoryStartupBytes $ memoryStartupBytes - NewVHDPath $ vhdPath - NewVHDSizeBytes $ newVHDSizeBytes - SwitchName $ switchName
Hyper - V \ New - VHD - Path $ vhdPath - SizeBytes $ newVHDSizeBytes - BlockSizeBytes $ vhdBlockSizeBytes
Hyper - V \ New - VM - Name $ vmName - Path $ path - MemoryStartupBytes $ memoryStartupBytes - VHDPath $ vhdPath - SwitchName $ switchName
}
`
var ps powershell . PowerShellCmd
if err := ps . Run ( script , vmName , path , harddrivePath , vhdRoot , strconv . FormatInt ( ram , 10 ) , strconv . FormatInt ( diskSize , 10 ) , s witchName, strconv . FormatBool ( diffDisks ) ) ; err != nil {
if err := ps . Run ( script , vmName , path , harddrivePath , vhdRoot , strconv . FormatInt ( ram , 10 ) , strconv . FormatInt ( diskSize , 10 ) , s trconv. FormatInt ( diskBlockSize , 10 ) , s witchName, strconv . FormatBool ( diffDisks ) ) ; err != nil {
return err
}
@ -872,16 +874,16 @@ Hyper-V\Get-VMNetworkAdapter -VMName $vmName | Hyper-V\Connect-VMNetworkAdapter
return err
}
func AddVirtualMachineHardDiskDrive ( vmName string , vhdRoot string , vhdName string , vhdSizeBytes int64 , controllerType string ) error {
func AddVirtualMachineHardDiskDrive ( vmName string , vhdRoot string , vhdName string , vhdSizeBytes int64 , vhdBlockSize int64 , controllerType string ) error {
var script = `
param ( [ string ] $ vmName , [ string ] $ vhdRoot , [ string ] $ vhdName , [ string ] $ vhdSizeInBytes , [ string ] $ controllerType )
param ( [ string ] $ vmName , [ string ] $ vhdRoot , [ string ] $ vhdName , [ string ] $ vhdSizeInBytes , [ string ] $ vhdBlockSizeInByte [ string ] $ controllerType )
$ vhdPath = Join - Path - Path $ vhdRoot - ChildPath $ vhdName
New - VHD $ vhdPath - SizeBytes $ vhdSizeInBytes
Hyper - V \ New - VHD - path $ vhdPath - SizeBytes $ vhdSizeInBytes - BlockSizeBytes $ vhdBlockSizeInByte
Hyper - V \ Add - VMHardDiskDrive - VMName $ vmName - path $ vhdPath - controllerType $ controllerType
`
var ps powershell . PowerShellCmd
err := ps . Run ( script , vmName , vhdRoot , vhdName , strconv . FormatInt ( vhdSizeBytes , 10 ) , controllerType)
err := ps . Run ( script , vmName , vhdRoot , vhdName , strconv . FormatInt ( vhdSizeBytes , 10 ) , strconv. FormatInt ( vhdBlockSize , 10 ) , controllerType)
return err
}