Ensure Hyper-V cmdlets are fully qualified
+ This disambuguates calls to the Hyper-V functions for the Hyper-V provider. The ambiguity of some commands - such as `Get-VM` - causes the Hyper-V provider to fail on systems where VMware PowerCLI is installed. This change ensures that all calls to Hyper-V specific cmdlets or functions are prepended by `Hyper-V\`. This ensures the correct cmdlet calls are being made. + Resolves #8862.
This commit is contained in:
parent
2b4a69964e
commit
9e1d05641f
|
@ -2,7 +2,7 @@
|
||||||
$Dir = Split-Path $script:MyInvocation.MyCommand.Path
|
$Dir = Split-Path $script:MyInvocation.MyCommand.Path
|
||||||
. ([System.IO.Path]::Combine($Dir, "utils\write_messages.ps1"))
|
. ([System.IO.Path]::Combine($Dir, "utils\write_messages.ps1"))
|
||||||
|
|
||||||
$check = $(-Not (-Not (Get-Command "Get-VMSwitch" -errorAction SilentlyContinue)))
|
$check = $(-Not (-Not (Get-Command "Hyper-V\Get-VMSwitch" -errorAction SilentlyContinue)))
|
||||||
$result = @{
|
$result = @{
|
||||||
result = $check
|
result = $check
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,4 +6,4 @@ Param(
|
||||||
[string]$Destination
|
[string]$Destination
|
||||||
)
|
)
|
||||||
|
|
||||||
New-VHD -Path $Destination -ParentPath $Source -ErrorAction Stop
|
Hyper-V\New-VHD -Path $Destination -ParentPath $Source -ErrorAction Stop
|
||||||
|
|
|
@ -4,5 +4,5 @@ Param(
|
||||||
[string]$SnapName
|
[string]$SnapName
|
||||||
)
|
)
|
||||||
|
|
||||||
$VM = Get-VM -Id $VmId -ErrorAction "Stop"
|
$VM = Hyper-V\Get-VM -Id $VmId -ErrorAction "Stop"
|
||||||
Checkpoint-VM $VM -SnapshotName $SnapName
|
Hyper-V\Checkpoint-VM $VM -SnapshotName $SnapName
|
||||||
|
|
|
@ -4,5 +4,5 @@ Param(
|
||||||
[string]$SnapName
|
[string]$SnapName
|
||||||
)
|
)
|
||||||
|
|
||||||
$VM = Get-VM -Id $VmId -ErrorAction "Stop"
|
$VM = Hyper-V\Get-VM -Id $VmId -ErrorAction "Stop"
|
||||||
Remove-VMSnapshot $VM -Name $SnapName
|
Hyper-V\Remove-VMSnapshot $VM -Name $SnapName
|
||||||
|
|
|
@ -3,5 +3,5 @@ Param(
|
||||||
[string]$VmId
|
[string]$VmId
|
||||||
)
|
)
|
||||||
|
|
||||||
$VM = Get-VM -Id $VmId -ErrorAction "Stop"
|
$VM = Hyper-V\Get-VM -Id $VmId -ErrorAction "Stop"
|
||||||
Remove-VM $VM -Force
|
Hyper-V\Remove-VM $VM -Force
|
||||||
|
|
|
@ -5,8 +5,8 @@ Param(
|
||||||
[string]$Path
|
[string]$Path
|
||||||
)
|
)
|
||||||
|
|
||||||
$vm = Get-VM -Id $VmId -ErrorAction "Stop"
|
$vm = Hyper-V\Get-VM -Id $VmId -ErrorAction "Stop"
|
||||||
$vm | Export-VM -Path $Path
|
$vm | Hyper-V\Export-VM -Path $Path
|
||||||
|
|
||||||
# Prepare directory structure for box import
|
# Prepare directory structure for box import
|
||||||
$name = $vm.Name
|
$name = $vm.Name
|
||||||
|
|
|
@ -45,7 +45,7 @@ function Sync-Remote-Machine($machine, $remove_files, $copy_files, $host_path, $
|
||||||
$from = $host_path + $item
|
$from = $host_path + $item
|
||||||
$to = $guest_path + $item
|
$to = $guest_path + $item
|
||||||
# Copy VM can also take a VM object
|
# Copy VM can also take a VM object
|
||||||
Copy-VMFile -VM $machine -SourcePath $from -DestinationPath $to -CreateFullPath -FileSource Host -Force
|
Hyper-V\Copy-VMFile -VM $machine -SourcePath $from -DestinationPath $to -CreateFullPath -FileSource Host -Force
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ function Get-Empty-folders-From-Source($host_path) {
|
||||||
|
|
||||||
$delimiter = " || "
|
$delimiter = " || "
|
||||||
|
|
||||||
$machine = Get-VM -Id $vm_id
|
$machine = Hyper-V\Get-VM -Id $vm_id
|
||||||
|
|
||||||
# FIXME: PowerShell guys please fix this.
|
# FIXME: PowerShell guys please fix this.
|
||||||
# The below script checks for all VMIntegrationService which are not enabled
|
# The below script checks for all VMIntegrationService which are not enabled
|
||||||
|
@ -75,7 +75,7 @@ $machine = Get-VM -Id $vm_id
|
||||||
# When when all the services are enabled this throws an error.
|
# When when all the services are enabled this throws an error.
|
||||||
# Enable VMIntegrationService to true
|
# Enable VMIntegrationService to true
|
||||||
try {
|
try {
|
||||||
Get-VM -Id $vm_id | Get-VMIntegrationService -Name "Guest Service Interface" | Enable-VMIntegrationService -Passthru
|
Hyper-V\Get-VM -Id $vm_id | Hyper-V\Get-VMIntegrationService -Name "Guest Service Interface" | Hyper-V\Enable-VMIntegrationService -Passthru
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,8 @@ Param(
|
||||||
$Dir = Split-Path $script:MyInvocation.MyCommand.Path
|
$Dir = Split-Path $script:MyInvocation.MyCommand.Path
|
||||||
. ([System.IO.Path]::Combine($Dir, "utils\write_messages.ps1"))
|
. ([System.IO.Path]::Combine($Dir, "utils\write_messages.ps1"))
|
||||||
|
|
||||||
$vm = Get-VM -Id $VmId -ErrorAction "Stop"
|
$vm = Hyper-V\Get-VM -Id $VmId -ErrorAction "Stop"
|
||||||
$networks = Get-VMNetworkAdapter -VM $vm
|
$networks = Hyper-V\Get-VMNetworkAdapter -VM $vm
|
||||||
foreach ($network in $networks) {
|
foreach ($network in $networks) {
|
||||||
if ($network.IpAddresses.Length -gt 0) {
|
if ($network.IpAddresses.Length -gt 0) {
|
||||||
foreach ($ip_address in $network.IpAddresses) {
|
foreach ($ip_address in $network.IpAddresses) {
|
||||||
|
|
|
@ -8,8 +8,8 @@ $Dir = Split-Path $script:MyInvocation.MyCommand.Path
|
||||||
. ([System.IO.Path]::Combine($Dir, "utils\write_messages.ps1"))
|
. ([System.IO.Path]::Combine($Dir, "utils\write_messages.ps1"))
|
||||||
|
|
||||||
$ip_address = ""
|
$ip_address = ""
|
||||||
$vm = Get-VM -Id $VmId -ErrorAction "Stop"
|
$vm = Hyper-V\Get-VM -Id $VmId -ErrorAction "Stop"
|
||||||
$networks = Get-VMNetworkAdapter -VM $vm
|
$networks = Hyper-V\Get-VMNetworkAdapter -VM $vm
|
||||||
foreach ($network in $networks) {
|
foreach ($network in $networks) {
|
||||||
if ($network.MacAddress -gt 0) {
|
if ($network.MacAddress -gt 0) {
|
||||||
$mac_address = $network.MacAddress
|
$mac_address = $network.MacAddress
|
||||||
|
|
|
@ -7,6 +7,6 @@
|
||||||
$Dir = Split-Path $script:MyInvocation.MyCommand.Path
|
$Dir = Split-Path $script:MyInvocation.MyCommand.Path
|
||||||
. ([System.IO.Path]::Combine($Dir, "utils\write_messages.ps1"))
|
. ([System.IO.Path]::Combine($Dir, "utils\write_messages.ps1"))
|
||||||
|
|
||||||
$Switches = @(Get-VMSwitch `
|
$Switches = @(Hyper-V\Get-VMSwitch `
|
||||||
| Select-Object Name,SwitchType,NetAdapterInterfaceDescription)
|
| Select-Object Name,SwitchType,NetAdapterInterfaceDescription)
|
||||||
Write-Output-Message $(ConvertTo-JSON $Switches)
|
Write-Output-Message $(ConvertTo-JSON $Switches)
|
||||||
|
|
|
@ -28,7 +28,7 @@ if($HyperVVersion -lt ([version]'10.0')) {
|
||||||
$ExceptionType = [Microsoft.HyperV.PowerShell.VirtualizationException]
|
$ExceptionType = [Microsoft.HyperV.PowerShell.VirtualizationException]
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$VM = Get-VM -Id $VmId -ErrorAction "Stop"
|
$VM = Hyper-V\Get-VM -Id $VmId -ErrorAction "Stop"
|
||||||
$State = $VM.state
|
$State = $VM.state
|
||||||
$Status = $VM.status
|
$Status = $VM.status
|
||||||
} catch [Exception] {
|
} catch [Exception] {
|
||||||
|
|
|
@ -30,7 +30,7 @@ $VmProperties = @{
|
||||||
VirtualMachinePath = $data_path
|
VirtualMachinePath = $data_path
|
||||||
}
|
}
|
||||||
|
|
||||||
$vmConfig = (Compare-VM -Copy -GenerateNewID @VmProperties)
|
$vmConfig = (Hyper-V\Compare-VM -Copy -GenerateNewID @VmProperties)
|
||||||
|
|
||||||
$generation = $vmConfig.VM.Generation
|
$generation = $vmConfig.VM.Generation
|
||||||
|
|
||||||
|
@ -43,13 +43,13 @@ if (!$vmname) {
|
||||||
|
|
||||||
if (!$cpus) {
|
if (!$cpus) {
|
||||||
# Get the processorcount of the VM
|
# Get the processorcount of the VM
|
||||||
$processors = (Get-VMProcessor -VM $vmConfig.VM).Count
|
$processors = (Hyper-V\Get-VMProcessor -VM $vmConfig.VM).Count
|
||||||
}else {
|
}else {
|
||||||
$processors = $cpus
|
$processors = $cpus
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetUniqueName($name) {
|
function GetUniqueName($name) {
|
||||||
Get-VM | ForEach-Object -Process {
|
Hyper-V\Get-VM | ForEach-Object -Process {
|
||||||
if ($name -eq $_.Name) {
|
if ($name -eq $_.Name) {
|
||||||
$name = $name + "_1"
|
$name = $name + "_1"
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ do {
|
||||||
} while ($vm_name -ne $name)
|
} while ($vm_name -ne $name)
|
||||||
|
|
||||||
if (!$memory) {
|
if (!$memory) {
|
||||||
$configMemory = Get-VMMemory -VM $vmConfig.VM
|
$configMemory = Hyper-V\Get-VMMemory -VM $vmConfig.VM
|
||||||
$dynamicmemory = $configMemory.DynamicMemoryEnabled
|
$dynamicmemory = $configMemory.DynamicMemoryEnabled
|
||||||
|
|
||||||
$MemoryMaximumBytes = ($configMemory.Maximum)
|
$MemoryMaximumBytes = ($configMemory.Maximum)
|
||||||
|
@ -84,46 +84,46 @@ if (!$memory) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$switchname) {
|
if (!$switchname) {
|
||||||
$switchname = (Get-VMNetworkAdapter -VM $vmConfig.VM).SwitchName
|
$switchname = (Hyper-V\Get-VMNetworkAdapter -VM $vmConfig.VM).SwitchName
|
||||||
}
|
}
|
||||||
|
|
||||||
# Enable nested virtualization if configured
|
# Enable nested virtualization if configured
|
||||||
if ($enable_virtualization_extensions -eq "True") {
|
if ($enable_virtualization_extensions -eq "True") {
|
||||||
Set-VMProcessor -VM $vmConfig.VM -ExposeVirtualizationExtensions $true
|
Hyper-V\Set-VMProcessor -VM $vmConfig.VM -ExposeVirtualizationExtensions $true
|
||||||
}
|
}
|
||||||
|
|
||||||
$vmNetworkAdapter = Get-VMNetworkAdapter -VM $vmConfig.VM
|
$vmNetworkAdapter = Hyper-V\Get-VMNetworkAdapter -VM $vmConfig.VM
|
||||||
Connect-VMNetworkAdapter -VMNetworkAdapter $vmNetworkAdapter -SwitchName $switchname
|
Hyper-V\Connect-VMNetworkAdapter -VMNetworkAdapter $vmNetworkAdapter -SwitchName $switchname
|
||||||
Set-VM -VM $vmConfig.VM -NewVMName $vm_name
|
Hyper-V\Set-VM -VM $vmConfig.VM -NewVMName $vm_name
|
||||||
Set-VM -VM $vmConfig.VM -ErrorAction "Stop"
|
Hyper-V\Set-VM -VM $vmConfig.VM -ErrorAction "Stop"
|
||||||
Set-VM -VM $vmConfig.VM -ProcessorCount $processors
|
Hyper-V\Set-VM -VM $vmConfig.VM -ProcessorCount $processors
|
||||||
|
|
||||||
if ($dynamicmemory) {
|
if ($dynamicmemory) {
|
||||||
Set-VM -VM $vmConfig.VM -DynamicMemory
|
Hyper-V\Set-VM -VM $vmConfig.VM -DynamicMemory
|
||||||
Set-VM -VM $vmConfig.VM -MemoryMinimumBytes $MemoryMinimumBytes -MemoryMaximumBytes $MemoryMaximumBytes -MemoryStartupBytes $MemoryStartupBytes
|
Hyper-V\Set-VM -VM $vmConfig.VM -MemoryMinimumBytes $MemoryMinimumBytes -MemoryMaximumBytes $MemoryMaximumBytes -MemoryStartupBytes $MemoryStartupBytes
|
||||||
} else {
|
} else {
|
||||||
Set-VM -VM $vmConfig.VM -StaticMemory
|
Hyper-V\Set-VM -VM $vmConfig.VM -StaticMemory
|
||||||
Set-VM -VM $vmConfig.VM -MemoryStartupBytes $MemoryStartupBytes
|
Hyper-V\Set-VM -VM $vmConfig.VM -MemoryStartupBytes $MemoryStartupBytes
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($notes) {
|
if ($notes) {
|
||||||
Set-VM -VM $vmConfig.VM -Notes $notes
|
Hyper-V\Set-VM -VM $vmConfig.VM -Notes $notes
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($auto_start_action) {
|
if ($auto_start_action) {
|
||||||
Set-VM -VM $vmConfig.VM -AutomaticStartAction $auto_start_action
|
Hyper-V\Set-VM -VM $vmConfig.VM -AutomaticStartAction $auto_start_action
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($auto_stop_action) {
|
if ($auto_stop_action) {
|
||||||
Set-VM -VM $vmConfig.VM -AutomaticStopAction $auto_stop_action
|
Hyper-V\Set-VM -VM $vmConfig.VM -AutomaticStopAction $auto_stop_action
|
||||||
}
|
}
|
||||||
|
|
||||||
# Only set EFI secure boot for Gen 2 machines, not gen 1
|
# Only set EFI secure boot for Gen 2 machines, not gen 1
|
||||||
if ($generation -ne 1) {
|
if ($generation -ne 1) {
|
||||||
Set-VMFirmware -VM $vmConfig.VM -EnableSecureBoot (Get-VMFirmware -VM $vmConfig.VM).SecureBoot
|
Hyper-V\Set-VMFirmware -VM $vmConfig.VM -EnableSecureBoot (Hyper-V\Get-VMFirmware -VM $vmConfig.VM).SecureBoot
|
||||||
}
|
}
|
||||||
|
|
||||||
$report = Compare-VM -CompatibilityReport $vmConfig
|
$report = Hyper-V\Compare-VM -CompatibilityReport $vmConfig
|
||||||
|
|
||||||
# Stop if there are incompatibilities
|
# Stop if there are incompatibilities
|
||||||
if($report.Incompatibilities.Length -gt 0){
|
if($report.Incompatibilities.Length -gt 0){
|
||||||
|
@ -133,9 +133,9 @@ if($report.Incompatibilities.Length -gt 0){
|
||||||
|
|
||||||
if($differencing_disk){
|
if($differencing_disk){
|
||||||
# Get all controller on the VM, first scsi, then IDE if it is a Gen 1 device
|
# Get all controller on the VM, first scsi, then IDE if it is a Gen 1 device
|
||||||
$controllers = Get-VMScsiController -VM $vmConfig.VM
|
$controllers = Hyper-V\Get-VMScsiController -VM $vmConfig.VM
|
||||||
if($generation -eq 1){
|
if($generation -eq 1){
|
||||||
$controllers = @($controllers) + @(Get-VMIdeController -VM $vmConfig.VM)
|
$controllers = @($controllers) + @(Hyper-V\Get-VMIdeController -VM $vmConfig.VM)
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($controller in $controllers){
|
foreach($controller in $controllers){
|
||||||
|
@ -143,17 +143,17 @@ if($differencing_disk){
|
||||||
if([System.IO.Path]::GetFileName($drive.Path) -eq [System.IO.Path]::GetFileName($source_path)){
|
if([System.IO.Path]::GetFileName($drive.Path) -eq [System.IO.Path]::GetFileName($source_path)){
|
||||||
# Remove the old disk and replace it with a differencing version
|
# Remove the old disk and replace it with a differencing version
|
||||||
$path = $drive.Path
|
$path = $drive.Path
|
||||||
Remove-VMHardDiskDrive $drive
|
Hyper-V\Remove-VMHardDiskDrive $drive
|
||||||
New-VHD -Path $dest_path -ParentPath $source_path -ErrorAction Stop
|
Hyper-V\New-VHD -Path $dest_path -ParentPath $source_path -ErrorAction Stop
|
||||||
Add-VMHardDiskDrive -VM $vmConfig.VM -Path $dest_path
|
Hyper-V\Add-VMHardDiskDrive -VM $vmConfig.VM -Path $dest_path
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Import-VM -CompatibilityReport $vmConfig
|
Hyper-V\Import-VM -CompatibilityReport $vmConfig
|
||||||
|
|
||||||
$vm_id = (Get-VM $vm_name).id.guid
|
$vm_id = (Hyper-V\Get-VM $vm_name).id.guid
|
||||||
$resultHash = @{
|
$resultHash = @{
|
||||||
name = $vm_name
|
name = $vm_name
|
||||||
id = $vm_id
|
id = $vm_id
|
||||||
|
|
|
@ -37,7 +37,7 @@ if (!$cpus) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetUniqueName($name) {
|
function GetUniqueName($name) {
|
||||||
Get-VM | ForEach-Object -Process {
|
Hyper-V\Get-VM | ForEach-Object -Process {
|
||||||
if ($name -eq $_.Name) {
|
if ($name -eq $_.Name) {
|
||||||
$name = $name + "_1"
|
$name = $name + "_1"
|
||||||
}
|
}
|
||||||
|
@ -118,13 +118,13 @@ $vm_params = @{
|
||||||
}
|
}
|
||||||
|
|
||||||
# Generation parameter was added in ps v4
|
# Generation parameter was added in ps v4
|
||||||
if((get-command New-VM).Parameters.Keys.Contains("generation")) {
|
if((get-command Hyper-V\New-VM).Parameters.Keys.Contains("generation")) {
|
||||||
$vm_params.Generation = $generation
|
$vm_params.Generation = $generation
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create the VM using the values in the hash map
|
# Create the VM using the values in the hash map
|
||||||
|
|
||||||
$vm = New-VM @vm_params
|
$vm = Hyper-V\New-VM @vm_params
|
||||||
|
|
||||||
$notes = (Select-Xml -xml $vmconfig -XPath "//notes").node.'#text'
|
$notes = (Select-Xml -xml $vmconfig -XPath "//notes").node.'#text'
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ if ($auto_stop_action) {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set the values on the VM
|
# Set the values on the VM
|
||||||
$vm | Set-VM @more_vm_params -Passthru
|
$vm | Hyper-V\Set-VM @more_vm_params -Passthru
|
||||||
|
|
||||||
# Add drives to the virtual machine
|
# Add drives to the virtual machine
|
||||||
$controllers = Select-Xml -xml $vmconfig -xpath "//*[starts-with(name(.),'controller')]"
|
$controllers = Select-Xml -xml $vmconfig -xpath "//*[starts-with(name(.),'controller')]"
|
||||||
|
@ -165,15 +165,15 @@ $controllers = Select-Xml -xml $vmconfig -xpath "//*[starts-with(name(.),'contro
|
||||||
if ($generation -ne 1) {
|
if ($generation -ne 1) {
|
||||||
# Set EFI secure boot
|
# Set EFI secure boot
|
||||||
if ($secure_boot_enabled -eq "True") {
|
if ($secure_boot_enabled -eq "True") {
|
||||||
Set-VMFirmware -VM $vm -EnableSecureBoot On
|
Hyper-V\Set-VMFirmware -VM $vm -EnableSecureBoot On
|
||||||
} else {
|
} else {
|
||||||
Set-VMFirmware -VM $vm -EnableSecureBoot Off
|
Hyper-V\Set-VMFirmware -VM $vm -EnableSecureBoot Off
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Enable nested virtualization if configured
|
# Enable nested virtualization if configured
|
||||||
if ($enable_virtualization_extensions -eq "True") {
|
if ($enable_virtualization_extensions -eq "True") {
|
||||||
Set-VMProcessor -VM $vm -ExposeVirtualizationExtensions $true
|
Hyper-V\Set-VMProcessor -VM $vm -ExposeVirtualizationExtensions $true
|
||||||
}
|
}
|
||||||
|
|
||||||
# A regular expression pattern to pull the number from controllers
|
# A regular expression pattern to pull the number from controllers
|
||||||
|
@ -206,12 +206,12 @@ foreach ($controller in $controllers) {
|
||||||
|
|
||||||
if ($drivetype -eq 'VHD') {
|
if ($drivetype -eq 'VHD') {
|
||||||
$addDriveParam.add("ControllerType",$ControllerType)
|
$addDriveParam.add("ControllerType",$ControllerType)
|
||||||
$vm | Add-VMHardDiskDrive @AddDriveparam
|
$vm | Hyper-V\Add-VMHardDiskDrive @AddDriveparam
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$vm_id = (Get-VM $vm_name).id.guid
|
$vm_id = (Hyper-V\Get-VM $vm_name).id.guid
|
||||||
$resultHash = @{
|
$resultHash = @{
|
||||||
name = $vm_name
|
name = $vm_name
|
||||||
id = $vm_id
|
id = $vm_id
|
||||||
|
|
|
@ -3,8 +3,8 @@ Param(
|
||||||
[string]$VmId
|
[string]$VmId
|
||||||
)
|
)
|
||||||
|
|
||||||
$VM = Get-VM -Id $VmId -ErrorAction "Stop"
|
$VM = Hyper-V\Get-VM -Id $VmId -ErrorAction "Stop"
|
||||||
$Snapshots = @(Get-VMSnapshot $VM | Select-Object Name)
|
$Snapshots = @(Hyper-V\Get-VMSnapshot $VM | Select-Object Name)
|
||||||
$result = ConvertTo-json $Snapshots
|
$result = ConvertTo-json $Snapshots
|
||||||
|
|
||||||
Write-Host "===Begin-Output==="
|
Write-Host "===Begin-Output==="
|
||||||
|
|
|
@ -4,5 +4,5 @@ Param(
|
||||||
[string]$SnapName
|
[string]$SnapName
|
||||||
)
|
)
|
||||||
|
|
||||||
$VM = Get-VM -Id $VmId -ErrorAction "Stop"
|
$VM = Hyper-V\Get-VM -Id $VmId -ErrorAction "Stop"
|
||||||
Restore-VMSnapshot $VM -Name $SnapName -Confirm:$false
|
Hyper-V\Restore-VMSnapshot $VM -Name $SnapName -Confirm:$false
|
||||||
|
|
|
@ -3,5 +3,5 @@ Param(
|
||||||
[string]$VmId
|
[string]$VmId
|
||||||
)
|
)
|
||||||
|
|
||||||
$VM = Get-VM -Id $VmId -ErrorAction "Stop"
|
$VM = Hyper-V\Get-VM -Id $VmId -ErrorAction "Stop"
|
||||||
Resume-VM $VM
|
Hyper-V\Resume-VM $VM
|
||||||
|
|
|
@ -10,8 +10,8 @@ $modules += $presentDir + "\utils\write_messages.ps1"
|
||||||
forEach ($module in $modules) { . $module }
|
forEach ($module in $modules) { . $module }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$vm = Get-VM -Id $VmId -ErrorAction "stop"
|
$vm = Hyper-V\Get-VM -Id $VmId -ErrorAction "stop"
|
||||||
Set-VMNetworkAdapter $vm -StaticMacAddress $Mac -ErrorAction "stop"
|
Hyper-V\Set-VMNetworkAdapter $vm -StaticMacAddress $Mac -ErrorAction "stop"
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Write-Error-Message "Failed to set VM's MAC address $_"
|
Write-Error-Message "Failed to set VM's MAC address $_"
|
||||||
|
|
|
@ -10,8 +10,8 @@ $modules += $presentDir + "\utils\write_messages.ps1"
|
||||||
forEach ($module in $modules) { . $module }
|
forEach ($module in $modules) { . $module }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$vm = Get-VM -Id $VmId -ErrorAction "stop"
|
$vm = Hyper-V\Get-VM -Id $VmId -ErrorAction "stop"
|
||||||
Set-VMNetworkAdapterVlan $vm -Access -Vlanid $VlanId
|
Hyper-V\Set-VMNetworkAdapterVlan $vm -Access -Vlanid $VlanId
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Write-Error-Message "Failed to set VM's Vlan ID $_"
|
Write-Error-Message "Failed to set VM's Vlan ID $_"
|
||||||
|
|
|
@ -12,7 +12,7 @@ param (
|
||||||
$Dir = Split-Path $script:MyInvocation.MyCommand.Path
|
$Dir = Split-Path $script:MyInvocation.MyCommand.Path
|
||||||
. ([System.IO.Path]::Combine($Dir, "utils\write_messages.ps1"))
|
. ([System.IO.Path]::Combine($Dir, "utils\write_messages.ps1"))
|
||||||
|
|
||||||
$vm = Get-VM -Id $VmId -ErrorAction "stop"
|
$vm = Hyper-V\Get-VM -Id $VmId -ErrorAction "stop"
|
||||||
|
|
||||||
# Set the service based on value
|
# Set the service based on value
|
||||||
function VmSetService
|
function VmSetService
|
||||||
|
@ -21,10 +21,10 @@ function VmSetService
|
||||||
|
|
||||||
if ($Value -ne $null){
|
if ($Value -ne $null){
|
||||||
if($Value -eq "true"){
|
if($Value -eq "true"){
|
||||||
Enable-VMIntegrationService -VM $Vm -Name $Name
|
Hyper-V\Enable-VMIntegrationService -VM $Vm -Name $Name
|
||||||
}
|
}
|
||||||
if($Value -eq "false"){
|
if($Value -eq "false"){
|
||||||
Disable-VMIntegrationService -VM $Vm -Name $Name
|
Hyper-V\Disable-VMIntegrationService -VM $Vm -Name $Name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@ $modules += $presentDir + "\utils\write_messages.ps1"
|
||||||
forEach ($module in $modules) { . $module }
|
forEach ($module in $modules) { . $module }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$vm = Get-VM -Id $VmId -ErrorAction "stop"
|
$vm = Hyper-V\Get-VM -Id $VmId -ErrorAction "stop"
|
||||||
Start-VM $vm -ErrorAction "stop"
|
Hyper-V\Start-VM $vm -ErrorAction "stop"
|
||||||
$state = $vm.state
|
$state = $vm.state
|
||||||
$status = $vm.status
|
$status = $vm.status
|
||||||
$name = $vm.name
|
$name = $vm.name
|
||||||
|
|
|
@ -4,5 +4,5 @@ Param(
|
||||||
)
|
)
|
||||||
|
|
||||||
# Shuts down virtual machine regardless of any unsaved application data
|
# Shuts down virtual machine regardless of any unsaved application data
|
||||||
$VM = Get-VM -Id $VmId -ErrorAction "Stop"
|
$VM = Hyper-V\Get-VM -Id $VmId -ErrorAction "Stop"
|
||||||
Stop-VM $VM -Force
|
Hyper-V\Stop-VM $VM -Force
|
||||||
|
|
|
@ -3,5 +3,5 @@ Param(
|
||||||
[string]$VmId
|
[string]$VmId
|
||||||
)
|
)
|
||||||
|
|
||||||
$VM = Get-VM -Id $VmId -ErrorAction "Stop"
|
$VM = Hyper-V\Get-VM -Id $VmId -ErrorAction "Stop"
|
||||||
Suspend-VM $VM
|
Hyper-V\Suspend-VM $VM
|
||||||
|
|
Loading…
Reference in New Issue