### Start-VM Usage Examples Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/start-vm Examples demonstrating how to start a specific virtual machine or multiple virtual machines using wildcard patterns. ```powershell PS C:\> Start-VM -Name TestVM ``` ```powershell PS C:\> Start-VM -Name Test* ``` -------------------------------- ### Get-VMHostSupportedVersion Examples Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/get-vmhostsupportedversion Examples demonstrating how to retrieve all supported configurations or specifically the default configuration version. ```powershell PS C:\> Get-VMHostSupportedVersion ``` ```powershell PS C:\> Get-VMHostSupportedVersion -Default ``` -------------------------------- ### Get-VMReplicationServer Examples Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/get-vmreplicationserver Examples demonstrating how to retrieve replication configuration for the local server or a specific remote server. ```powershell PS C:\> Get-VMReplicationServer ``` ```powershell PS C:\> Get-VMReplicationServer server01.domain01.contoso.com ``` -------------------------------- ### Enable-VMMigration Usage Examples Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/enable-vmmigration Examples demonstrating how to enable live migration on a local host and a specific remote host. ```powershell PS C:\> Enable-VMMigration ``` ```powershell PS C:\> Enable-VMMigration -ComputerName TestVM -Passthru ``` -------------------------------- ### Get-VMMigrationNetwork Examples Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/get-vmmigrationnetwork Examples demonstrating how to retrieve migration networks using various filters. ```powershell PS C:\> Get-VMMigrationNetwork ``` ```powershell PS C:\> Get-VMMigrationNetwork -Priority 8 ``` ```powershell PS C:\> Get-VMMigrationNetwork 192.168.* ``` -------------------------------- ### Add-VMMigrationNetwork Examples Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/add-vmmigrationnetwork Examples demonstrating how to add IPv4 and IPv6 subnets for live migration, including setting priority. ```powershell PS C:\> Add-VMMigrationNetwork 192.168.0.1 ``` ```powershell PS C:\> Add-VMMigrationNetwork 192.168.10.0/24 ``` ```powershell PS C:\> Add-VMMigrationNetwork 2001:836c:6456:1c99::/32 ``` ```powershell PS C:\> Add-VMMigrationNetwork 2001:836c:6456:1c99::/64 -Priority 8 ``` -------------------------------- ### Add-VMRemoteFx3dVideoAdapter Examples Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/add-vmremotefx3dvideoadapter Examples demonstrating how to add a RemoteFX video adapter to a virtual machine by name or by piping a VM object. ```powershell PS C:\> Add-VMRemoteFx3dVideoAdapter -VMName Test ``` ```powershell PS C:\> Get-VM Test | Add-VMRemoteFx3dVideoAdapter ``` -------------------------------- ### Dismount-VHD Examples Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/dismount-vhd Practical examples showing how to dismount a VHD using a file path or a disk number. ```powershell PS C:\> Dismount-VHD -Path c:\test\testvhdx.vhdx ``` ```powershell PS C:\> Dismount-VHD -DiskNumber 6 ``` -------------------------------- ### Save-VM Usage Examples Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/save-vm Examples demonstrating how to save a specific virtual machine by name or a collection of virtual machines using pipeline input. ```powershell PS C:\> Save-VM -Name TestVM ``` ```powershell PS C:\> Get-VM -Name Win* | Save-VM ``` -------------------------------- ### Get-VMHostPartitionableGpu Examples Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/get-vmhostpartitionablegpu Common usage patterns for retrieving partitionable GPU information. ```powershell Get-VMHostPartitionableGpu ``` ```powershell Get-VMHostPartitionableGpu -ComputerName "MyHost" ``` ```powershell Get-VMHostPartitionableGpu -Name "GPUDeviceIDName" ``` ```powershell Get-VMHostPartitionableGpu | FL Name, ValidPartitionCounts ``` -------------------------------- ### Start-VMInitialReplication Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/start-vminitialreplication Starts the initial replication for a virtual machine. ```APIDOC ## Start-VMInitialReplication ### Description Starts the initial replication for a virtual machine. ### Parameters - **-UseBackup** (SwitchParameter) - Optional - Indicates that you want to use a copy of this virtual machine on the Replica server as the basis for the initial replication. - **-VM** (VirtualMachine[]) - Required (in VMObject set) - Specifies the virtual machine on which replication is to be started. - **-VMName** (String[]) - Required (in VMName set) - Specifies the name of the virtual machine on which replication is to be started. - **-VMReplication** (VMReplication[]) - Required (in VMReplication set) - Specifies an object that represents the replication to be started. - **-WhatIf** (SwitchParameter) - Optional - Shows what would happen if the cmdlet runs. ### Common Parameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. ``` -------------------------------- ### Start-VMInitialReplication Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/start-vminitialreplication Starts the initial replication of a virtual machine. ```APIDOC ## Start-VMInitialReplication ### Description Starts the initial replication of a virtual machine. This cmdlet can be used to schedule replication or specify a destination path for external media. ### Parameters - **AsJob** (SwitchParameter) - Optional - Runs the cmdlet as a background job. - **CimSession** (CimSession[]) - Optional - Runs the cmdlet in a remote session or on a remote computer. - **ComputerName** (String[]) - Optional - Specifies one or more Hyper-V hosts on which replication is to be started. - **Confirm** (SwitchParameter) - Optional - Prompts for confirmation before running the cmdlet. - **Credential** (PSCredential[]) - Optional - Specifies user accounts with permission to perform the action. - **DestinationPath** (String) - Optional - Specifies the path for initial replication files when using external media. - **InitialReplicationStartTime** (DateTime) - Optional - Specifies the time to start the initial replication. - **Passthru** (SwitchParameter) - Optional - Passes the virtual machine object through to the pipeline. ``` -------------------------------- ### Start-VM Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/start-vm Starts one or more virtual machines on a Hyper-V host. ```APIDOC ## Start-VM ### Description Starts the specified virtual machine(s) on a Hyper-V host. ### Parameters #### Name (String[]) - Required - Specifies the name of the virtual machine to be started. #### VM (VirtualMachine[]) - Required - Specifies the virtual machine object to be started. #### ComputerName (String[]) - Optional - Specifies one or more Hyper-V hosts on which the virtual machine is to be started. #### CimSession (CimSession[]) - Optional - Runs the cmdlet in a remote session or on a remote computer. #### Credential (PSCredential[]) - Optional - Specifies user accounts with permission to perform the action. #### AsJob (SwitchParameter) - Optional - Runs the cmdlet as a background job. #### Passthru (SwitchParameter) - Optional - Passes the VirtualMachine object through to the pipeline. #### Confirm (SwitchParameter) - Optional - Prompts for confirmation before running. #### WhatIf (SwitchParameter) - Optional - Shows what would happen if the cmdlet runs. ``` -------------------------------- ### Start-VMInitialReplication Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/start-vminitialreplication Starts the initial replication of a virtual machine. ```APIDOC ## Start-VMInitialReplication ### Description The Start-VMInitialReplication cmdlet starts replication of a virtual machine using the method you select. You also can schedule replication to start up to 7 days later. ### Syntax Start-VMInitialReplication [-VMName] [-ComputerName ] [-DestinationPath ] [-UseBackup] [-Confirm] [-WhatIf] Start-VMInitialReplication -VMReplication [-Confirm] [-WhatIf] ### Parameters - **VMName** (string[]) - Required - Specifies the name of the virtual machine. - **ComputerName** (string[]) - Optional - Specifies the name of the Hyper-V host. - **DestinationPath** (string) - Optional - Specifies the path to export the initial replication. - **UseBackup** (switch) - Optional - Indicates that the initial replication should use a backup. - **VMReplication** (VMReplication[]) - Required - Specifies the VMReplication object to start replication for. ``` -------------------------------- ### Start-VM Syntax Definitions Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/start-vm Syntax definitions for starting a virtual machine by name or by object reference. ```powershell Start-VM [-Name] [-CimSession ] [-ComputerName ] [-Credential ] [-AsJob] [-Passthru] [-WhatIf] [-Confirm] [] ``` ```powershell Start-VM [-VM] [-AsJob] [-Passthru] [-WhatIf] [-Confirm] [] ``` -------------------------------- ### Test a Virtual Hard Disk Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/test-vhd Example of testing a virtual hard disk chain starting from the specified file. ```powershell PS C:\> Test-VHD -Path Diff2.vhdx ``` -------------------------------- ### Create a virtual machine group Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/new-vmgroup Examples demonstrating how to create different types of virtual machine groups. ```PowerShell PS C:\> New-VMGroup -Name 'CollectionGroup07' -GroupType VMCollectionType ``` ```PowerShell PS C:\> New-VMGroup -Name 'ManagementCollectionGroup03' -GroupType ManagementCollectionType ``` -------------------------------- ### Get-VMFirmware Example Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/get-vmfirmware Retrieves the firmware object for a specific virtual machine by name. ```powershell PS C:\> Get-VMFirmware "Test VM" ``` -------------------------------- ### Start-VM Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/start-vm Starts a virtual machine using either the name of the VM or a virtual machine object. ```APIDOC ## Start-VM ### Description Starts a virtual machine. ### Syntax #### Name (Default) Start-VM [-Name] [-CimSession ] [-ComputerName ] [-Credential ] [-AsJob] [-Passthru] [-WhatIf] [-Confirm] #### VMObject Start-VM [-VM] [-AsJob] [-Passthru] [-WhatIf] [-Confirm] ### Parameters - **Name** (String[]) - Required - Specifies the name of the virtual machine to start. - **VM** (VirtualMachine[]) - Required - Specifies the virtual machine object to start. - **CimSession** (CimSession[]) - Optional - Runs the cmdlet in a remote session or on a remote computer. - **ComputerName** (String[]) - Optional - Specifies the computer on which the virtual machine is to be started. - **Credential** (PSCredential[]) - Optional - Specifies a user account that has permission to perform this action. - **AsJob** (SwitchParameter) - Optional - Runs the command as a background job. - **Passthru** (SwitchParameter) - Optional - Returns an object representing the item with which you are working. - **WhatIf** (SwitchParameter) - Optional - Shows what would happen if the cmdlet runs. - **Confirm** (SwitchParameter) - Optional - Prompts for confirmation before running the cmdlet. ### Examples #### Example 1 PS C:\> Start-VM -Name TestVM #### Example 2 PS C:\> Start-VM -Name Test* ``` -------------------------------- ### Get-VMHost Example Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/get-vmhost Retrieves the local Hyper-V host. ```powershell PS C:\> Get-VMHost ``` -------------------------------- ### Enable-VMEventing Example Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/enable-vmeventing Enables virtual machine eventing while suppressing the confirmation prompt. ```powershell PS C:\> Enable-VMEventing -Force ``` -------------------------------- ### Get-VMFloppyDiskDrive Example Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/get-vmfloppydiskdrive Retrieves the floppy disk drive configuration for a specific virtual machine. ```powershell PS C:\> Get-VMFloppyDiskDrive TestVM ``` -------------------------------- ### Retrieve integration services Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/get-vmintegrationservice Examples demonstrating how to filter and select specific integration services from virtual machines and snapshots. ```powershell PS C:\> Get-VMIntegrationService -VMName TestVM | Where-Object {$_.SecondaryOperationalStatus -eq 'ProtocolMismatch'} ``` ```powershell PS C:\> Get-VM -Name TestVM | Get-VMIntegrationService -Name Shutdown,VSS ``` ```powershell PS C:\> Get-VMSnapshot -VMName TestVM -Name 'Before applying updates' | Get-VMIntegrationService Shutdown,VSS ``` -------------------------------- ### Retrieve Virtual Switch Extensions Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/get-vmswitchextension Example showing how to pipe a virtual switch object into the Get-VMSwitchExtension cmdlet. ```powershell PS C:\> Get-VMSwitch InternalSwitch | Get-VMSwitchExtension ``` -------------------------------- ### Configure Replica Server Monitoring Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/set-vmreplicationserver Sets the monitoring interval and start time for the Replica server. ```PowerShell PS C:\> Set-VMReplicationServer -MonitoringInterval "12:00:00" -MonitoringStartTime "17:00:00" ``` -------------------------------- ### Get all virtual switch extensions Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/get-vmsystemswitchextension Retrieves all virtual switch extensions installed on the local system. ```powershell PS C:\> Get-VMSystemSwitchExtension ``` -------------------------------- ### Enable keyboard, video, and mouse support Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/enable-vmconsolesupport Example showing how to retrieve a virtual machine object and enable console support for it. ```powershell PS C:\> $VM = Get-VM -ComputerName "Server01" PS C:\> Enable-VMConsoleSupport -VM $VM ``` -------------------------------- ### Get information about a checkpoint Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/get-vhdsnapshot Retrieves details for a specific checkpoint identified by its GUID from a VHD set file. ```PowerShell Get-VHDSnapshot -Path "Data01.vhds" -SnapshotId 6c87351a-a39a-4581-b231-6d693b26485d ``` -------------------------------- ### Stop-VM Examples Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/stop-vm Common usage patterns for stopping virtual machines, including graceful and forced shutdown operations. ```powershell PS C:\> Stop-VM -Name TestVM ``` ```powershell PS C:\> Stop-VM -Name VM1 -Force ``` ```powershell PS C:\> Stop-VM -Name TestVM -TurnOff ``` -------------------------------- ### Get resource pools by name pattern Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/get-vmresourcepool Retrieves all resource pools on the local host with names starting with 'Test'. ```powershell PS C:\> Get-VMResourcePool Test* ``` -------------------------------- ### Get video settings for a virtual machine Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/get-vmvideo Example usage of Get-VMVideo to retrieve settings for a specific virtual machine by name. ```PowerShell PS C:\> Get-VMVideo -VMName "VM06" ``` -------------------------------- ### Create a basic virtual machine Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/new-vm Creates a new virtual machine with a specified name and startup memory. ```PowerShell New-VM -Name "VM01" -MemoryStartupBytes 512MB ``` -------------------------------- ### Stop-VMTrace Example Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/stop-vmtrace An example demonstrating how to stop tracing using the Stop-VMTrace cmdlet. ```powershell PS C:\> Stop-VMTrace ``` -------------------------------- ### Start initial replication from backup Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/start-vminitialreplication Configures replication settings and initiates initial replication using a restored backup copy of the virtual machine. ```powershell PS C:\> Enable-VMReplication VM01 -AsReplica -computername MyReplica.contoso.com PS C:\> Enable-VMReplication VMO1 -ReplicaServerName ReplicaServer01 -ReplicaServerPort 80 -AuthenticationType Kerberos -computername MyPrimary.contoso.comPS PS C:\> Start-VMInitialReplication VM01 -usebackup -computername MyPrimary.contoso.com ``` -------------------------------- ### Start-VMFailover Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/start-vmfailover Starts the failover process for a virtual machine. Use the -Prepare switch for planned failovers, which requires the primary virtual machine to be shut down. ```APIDOC ## Start-VMFailover ### Description Starts the failover process for a virtual machine. For planned failovers, use the -Prepare switch, noting that the primary virtual machine must be shut down first. ### Parameters - **-VM** (VirtualMachine[]) - Required - Specifies the virtual machine for which failover is to be started. - **-VMName** (String[]) - Required - Specifies the name of the virtual machine for which failover is to be started. - **-VMRecoverySnapshot** (VMSnapshot) - Optional - Specifies the recovery snapshot to use during a failover (not required for planned failover). - **-Prepare** (SwitchParameter) - Optional - Starts the planned failover on the primary virtual machine and replicates pending changes. - **-WhatIf** (SwitchParameter) - Optional - Shows what would happen if the cmdlet runs without actually executing it. ``` -------------------------------- ### Remove-VMDvdDrive Usage Examples Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/remove-vmdvddrive Examples demonstrating how to remove a specific DVD drive by controller location or by piping results from Get-VMDvdDrive. ```powershell PS C:\> Remove-VMDvdDrive -VMName TestVM -ControllerNumber 1 -ControllerLocation 0 ``` ```powershell PS C:\> Get-VMDvdDrive -VMName TestVM -ControllerNumber 1 | Remove-VMDvdDrive ``` -------------------------------- ### Retrieve GPU Partition Information Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/get-vmgpupartitionadapter Examples demonstrating how to fetch GPU partition adapter details using a VM object or a VM name. ```PowerShell $testvm = Get-VM "TestVM" Get-VMGpuPartitionAdapter -VM $testvm ``` ```PowerShell Get-VMGpuPartitionAdapter -VMName "TestVM" | FL InstancePath, Id, SupportsOutgoingLiveMigration ``` -------------------------------- ### Add-VMSwitch Usage Examples Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/add-vmswitch Demonstrates adding a virtual switch to a resource pool using either the switch name or a piped object. ```powershell PS C:\> Add-VMSwitch -Name Test -ResourcePoolName "Engineering Department" ``` ```powershell PS C:\> Get-VMSwitch -Name Test | Add-VMSwitch -ResourcePoolName "Engineering Department" ``` -------------------------------- ### Start-VMTrace Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/start-vmtrace Starts tracing to a file for advanced debugging purposes. ```APIDOC ## Start-VMTrace ### Description The Start-VMTrace cmdlet starts tracing to a file. You can use this information for advanced debugging. ### Syntax Start-VMTrace [-Level] [-TraceVerboseObjects] [-Path ] [] ### Parameters - **-Level** (TraceLevel) - Required - Specifies the level of tracing. Acceptable values: Off, Error, Warning, Info, Verbose. - **-Path** (String) - Optional - Specifies the path of the file where this cmdlet stores the trace information. - **-TraceVerboseObjects** (SwitchParameter) - Optional - Specifies that tracing uses verbose objects. ### Example PS C:\> Start-VMTrace -Level Error ``` -------------------------------- ### Start error tracing Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/start-vmtrace Initiates tracing at the Error level. ```powershell PS C:\> Start-VMTrace -Level Error ``` -------------------------------- ### Remove-VMStoragePath Example Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/remove-vmstoragepath Removes a specific path from a VHD resource pool. ```powershell PS C:\> Remove-VMStoragePath -Path D:\Test -ResourcePoolName VHD1 -ResourcePoolType VHD ``` -------------------------------- ### Start-VMFailover Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/start-vmfailover Initiates a failover for a virtual machine. This cmdlet supports parameters for test failovers, remote session management, and background job execution. ```APIDOC ## Start-VMFailover ### Description Starts a failover for a virtual machine. This can be used for standard failover or to create a test virtual machine for validation. ### Parameters - **-AsJob** (SwitchParameter) - Optional - Runs the cmdlet as a background job. - **-AsTest** (SwitchParameter) - Required (in VMName_Test, VMObject_Test, VMSnapshot_Test sets) - Creates a test virtual machine using the chosen recovery point. - **-CimSession** (CimSession[]) - Optional - Runs the cmdlet in a remote session or on a remote computer. - **-ComputerName** (String[]) - Optional - Specifies one or more Hyper-V hosts on which failover is to be started. - **-Confirm** (SwitchParameter) - Optional - Prompts for confirmation before running the cmdlet. - **-Credential** (PSCredential[]) - Optional - Specifies user accounts with permission to perform the action. - **-Passthru** (SwitchParameter) - Optional - Passes the virtual machine object through to the pipeline. ``` -------------------------------- ### Get-VMHostNumaNode Example Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/get-vmhostnumanode Retrieves the NUMA topology of the local Hyper-V host. ```PowerShell PS C:\> Get-VMHostNumaNode ``` -------------------------------- ### Disable-VMMigration Example Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/disable-vmmigration Disables live migration on the local Hyper-V host. ```powershell PS C:\> Disable-VMMigration ``` -------------------------------- ### Retrieve VM connection access Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/get-vmconnectaccess Examples demonstrating how to list connection access for all VMs, a specific VM, or a specific user. ```powershell PS C:\> Get-VMConnectAccess ``` ```powershell PS C:\> Get-VMConnectAccess -VMName VM1 ``` ```powershell PS C:\> Get-VMConnectAccess -UserName CONTOSO\John ``` -------------------------------- ### Measure-VMReplication Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/measure-vmreplication Gets replication statistics and information associated with a virtual machine. ```APIDOC ## Measure-VMReplication ### Description Gets replication statistics and information associated with a virtual machine. ### Syntax #### VMName (Default) Measure-VMReplication [[-VMName] ] [-CimSession ] [-ComputerName ] [-Credential ] [-ReplicaServerName ] [-PrimaryServerName ] [-ReplicationState ] [-ReplicationHealth ] [-ReplicationMode ] [-ReplicationRelationshipType ] [-TrustGroup ] [] #### VMObject Measure-VMReplication [-VM] [-ReplicationRelationshipType ] [] ``` -------------------------------- ### Configure a Replica Virtual Machine Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/enable-vmreplication Sets up a virtual machine as a replica and restricts allowed primary servers using a domain wildcard. ```powershell PS C:\> Enable-VMReplication VM01 -AsReplica -AllowedPrimaryServer *.domain01.contoso.com ``` -------------------------------- ### Get parent checkpoint Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/get-vmsnapshot Retrieves the immediate parent of a specific checkpoint. ```powershell PS C:\> $snapshot = Get-VMSnapshot -Name 'Before applying updates' -VMName TestVM PS C:\> Get-VMSnapshot -ParentOf $snapshot ``` -------------------------------- ### Create, mount, and format a VHD Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/new-vhd Creates a new VHD, mounts it, initializes the disk, creates a partition, and formats it with NTFS. ```powershell PS C:\> $vhdpath = "C:\VHDs\Test.vhdx" PS C:\> $vhdsize = 127GB PS C:\> New-VHD -Path $vhdpath -Dynamic -SizeBytes $vhdsize | Mount-VHD -Passthru |Initialize-Disk -Passthru |New-Partition -AssignDriveLetter -UseMaximumSize |Format-Volume -FileSystem NTFS -Confirm:$false -Force ``` -------------------------------- ### Get-VMSystemSwitchExtension Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/get-vmsystemswitchextension Retrieves the switch extensions installed on a virtual machine host. ```APIDOC ## Get-VMSystemSwitchExtension ### Description The Get-VMSystemSwitchExtension cmdlet gets the switch extensions installed on a virtual machine host. The returned switch extension does not contain embedded objects for features or an array of feature IDs. ### Parameters - **Name** (String[]) - Optional - Specifies the name of the switch extension to be retrieved. - **CimSession** (CimSession[]) - Optional - Runs the cmdlet in a remote session or on a remote computer. - **ComputerName** (String[]) - Optional - Specifies one or more Hyper-V hosts from which the switch extensions are to be retrieved. - **Credential** (PSCredential[]) - Optional - Specifies one or more user accounts that have permission to perform this action. ### Example ```powershell Get-VMSystemSwitchExtension ``` ### Outputs - **Microsoft.HyperV.PowerShell.SystemSwitchExtension** - The cmdlet returns objects representing the switch extensions. ``` -------------------------------- ### Compare-VM Parameters Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/compare-vm The Compare-VM cmdlet supports several parameters for specifying credentials, destination hosts, and CIM sessions to evaluate virtual machine compatibility. ```APIDOC ## Compare-VM Parameters ### -Credential - **Type**: PSCredential[] - **Description**: Specifies one or more user accounts that have permission to perform this action. The default is the current user. ### -DestinationCimSession - **Type**: CimSession - **Description**: Specifies the CIMSession on the Hyper-V host to which this cmdlet compares the virtual machine for compatibility. - **Mandatory**: True ### -DestinationCredential - **Type**: PSCredential - **Description**: Specifies a user account that has permission to perform this action. The default is the current user. ### -DestinationHost - **Type**: String - **Description**: Specifies the Hyper-V host to which the virtual machine is to be compared for compatibility. - **Mandatory**: True ``` -------------------------------- ### Troubleshoot and Import Incompatible Virtual Machine Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/compare-vm Demonstrates the workflow of identifying import failures, generating a compatibility report, resolving incompatibilities, and completing the import. ```powershell PS C:\> Import-VM -Path 'D:\vm1\Virtual Machines\53EAE599-4D3B-4923-B173-6AEA29CB7F42.XML' PS C:\> $report = Compare-VM -Path 'D:\vm1\Virtual Machines\53EAE599-4D3B-4923-B173-6AEA29CB7F42.XML' PS C:\> $report.Incompatibilities | Format-Table -AutoSize PS C:\> $report.Incompatibilities[0].Source | Disconnect-VMNetworkAdapter PS C:\> Compare-VM -CompatibilityReport $report PS C:\> $report PS C:\> import-vm -CompatibilityReport $report ``` -------------------------------- ### Retrieve BIOS for a Virtual Machine Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/get-vmbios Example showing how to retrieve the BIOS object for a specific virtual machine by name. ```powershell PS C:\> Get-VMBios TestVM ``` -------------------------------- ### Start-VMInitialReplication Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/start-vminitialreplication Starts replication of a virtual machine using various parameter sets including VMName, VM object, or VMReplication object. ```APIDOC ## Start-VMInitialReplication ### Description Starts replication of a virtual machine. ### Parameters - **VMName** (String[]) - Required (VMName set) - Specifies the name of the virtual machine. - **VM** (VirtualMachine[]) - Required (VMObject set) - Specifies the virtual machine object. - **VMReplication** (VMReplication[]) - Required (VMReplication set) - Specifies the replication object. - **ComputerName** (String[]) - Optional - Specifies the computer where the virtual machine is located. - **DestinationPath** (String) - Optional - Specifies the path for the initial replication. - **InitialReplicationStartTime** (DateTime) - Optional - Specifies the start time for the initial replication. - **UseBackup** (SwitchParameter) - Optional - Indicates that the initial replication should use a backup. - **AsJob** (SwitchParameter) - Optional - Runs the command as a background job. - **Passthru** (SwitchParameter) - Optional - Returns an object representing the item with which you are working. - **CimSession** (CimSession[]) - Optional - Runs the cmdlet in a remote session or on a remote computer. - **Credential** (PSCredential[]) - Optional - Specifies a user account that has permission to perform this action. - **WhatIf** (SwitchParameter) - Optional - Shows what would happen if the cmdlet runs. - **Confirm** (SwitchParameter) - Optional - Prompts for confirmation before running the cmdlet. ``` -------------------------------- ### Disable-VMEventing Example Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/disable-vmeventing Disables virtual machine eventing while suppressing the confirmation prompt. ```powershell PS C:\> Disable-VMEventing -Force ``` -------------------------------- ### Start-VMFailover Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/start-vmfailover The Start-VMFailover cmdlet initiates failover processes for Hyper-V virtual machines, including planned failovers and test failovers using recovery points. ```APIDOC ## Start-VMFailover ### Description Initiates a failover operation for a virtual machine. This can be used for standard failover to a recovery point, test failovers, or as part of a planned failover workflow. ### Parameters - **VMName** (string) - Optional - Specifies the name of the virtual machine. - **AsTest** (switch) - Optional - Indicates that the failover is a test failover. - **Prepare** (switch) - Optional - Prepares a primary virtual machine for a planned failover. - **ComputerName** (string) - Optional - Specifies the name of the computer where the virtual machine is located. ### Examples #### Fail over to a specific recovery point PS C:\> Get-VMSnapshot VM01 -Name Snapshot01 | Start-VMFailover #### Start a test failover PS C:\> Start-VMFailover VM01 -AsTest #### Perform a planned failover PS C:\> Start-VMFailover -Prepare -VMName VM01 -computername MyPrimary.contoso.com PS C:\> Start-VMFailover -VMName VM01 -computername MyReplica.contoso.com ``` -------------------------------- ### Start a test failover Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/start-vmfailover Initiates a test failover for the specified virtual machine. ```powershell PS C:\> Start-VMFailover VM01 -AsTest ``` -------------------------------- ### Resume a Virtual Machine by Name Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/resume-vm Example of using the Resume-VM cmdlet to resume a specific virtual machine identified by its name. ```powershell PS C:\> Resume-VM -Name TestVM ``` -------------------------------- ### Get child checkpoints Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/get-vmsnapshot Retrieves the immediate child checkpoints of a specific checkpoint. ```powershell PS C:\> $snapshot = Get-VMSnapshot -Name 'Before applying updates' -VMName TestVM PS C:\> Get-VMSnapshot -ChildOf $snapshot ``` -------------------------------- ### Start-VMFailover VMName Syntax Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/start-vmfailover Initiates failover for a virtual machine by name. ```powershell Start-VMFailover [-VMName] [-CimSession ] [-ComputerName ] [-Credential ] [-Prepare] [-AsJob] [-Passthru] [-WhatIf] [-Confirm] [] ``` -------------------------------- ### Get all checkpoints for a VM Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/get-vmsnapshot Retrieves all checkpoints associated with the specified virtual machine. ```powershell PS C:\> Get-VMSnapshot -VMName TestVM ``` -------------------------------- ### Get-VM Id Syntax Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/get-vm Retrieves virtual machines by their unique GUID identifier. ```PowerShell Get-VM [[-Id] ] [-CimSession ] [-ComputerName ] [-Credential ] [] ``` -------------------------------- ### Set the First Boot Device Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/set-vmfirmware Configures the virtual machine to boot from a specific network adapter object. ```powershell PS C:\> Set-VMFirmware "Test VM" -FirstBootDevice $vmNetworkAdapter ``` -------------------------------- ### Get-VMProcessor Example Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/get-vmprocessor Retrieves the processor object for a specific virtual machine named TestVM. ```powershell PS C:\> Get-VMProcessor TestVM ``` -------------------------------- ### Start-VMFailover Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/start-vmfailover Starts failover on a virtual machine using various parameter sets including VMName, VM object, or recovery snapshot. ```APIDOC ## Start-VMFailover ### Description Starts failover on a virtual machine. ### Parameters - **VMName** (String[]) - Required (in VMName/VMName_Test sets) - Specifies the name of the virtual machine. - **VM** (VirtualMachine[]) - Required (in VMObject/VMObject_Test sets) - Specifies the virtual machine object. - **VMRecoverySnapshot** (VMSnapshot) - Required (in VMSnapshot/VMSnapshot_Test sets) - Specifies the recovery snapshot. - **CimSession** (CimSession[]) - Optional - Runs the cmdlet in a remote session or on a remote computer. - **ComputerName** (String[]) - Optional - Specifies the computer on which the virtual machine is located. - **Credential** (PSCredential[]) - Optional - Specifies a user account that has permission to perform this action. - **Prepare** (SwitchParameter) - Optional - Prepares the virtual machine for failover. - **AsTest** (SwitchParameter) - Optional - Performs a test failover. - **AsJob** (SwitchParameter) - Optional - Runs the cmdlet as a background job. - **Passthru** (SwitchParameter) - Optional - Returns an object representing the item with which you are working. - **WhatIf** (SwitchParameter) - Optional - Shows what would happen if the cmdlet runs. - **Confirm** (SwitchParameter) - Optional - Prompts for confirmation before running the cmdlet. ``` -------------------------------- ### Add-VMStoragePath Example Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/add-vmstoragepath Adds a specific path to a storage resource pool of type VHD. ```powershell PS C:\> Add-VMStoragePath -Path D:\VHD -ResourcePoolName "Engineering Department" -ResourcePoolType VHD ``` -------------------------------- ### Compare-VM Register Syntax Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/compare-vm Syntax for registering a virtual machine from a specific path. ```powershell Compare-VM [-Path] [-CimSession ] [-ComputerName ] [-Credential ] [-AsJob] [-Register] [-WhatIf] [-Confirm] [] ``` -------------------------------- ### Enable-VMResourceMetering Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/enable-vmresourcemetering Starts collecting resource utilization data for a virtual machine or resource pool. ```APIDOC ## Enable-VMResourceMetering ### Description The Enable-VMResourceMetering cmdlet starts collecting resource utilization data for a virtual machine or resource pool. ### Parameters - **VMName** (String) - Optional - Specifies the name of the virtual machine. - **ResourcePoolName** (String) - Optional - Specifies the name of the resource pool. - **ResourcePoolType** (String[]) - Optional - Specifies the type of resource pool (e.g., Processor, VHD, Ethernet, Memory). ### Examples #### Enable metering for a virtual machine `Enable-VMResourceMetering -VMName TestVM` #### Enable metering for a resource pool `Enable-VMResourceMetering -ResourcePoolName TestResourcePool -ResourcePoolType Memory` ``` -------------------------------- ### Create a virtual machine based on an existing VM Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/new-vm Provisions a new virtual machine by retrieving configuration settings from an existing virtual machine. ```PowerShell $oldVM = Get-VM "PreviousVM" $memory = (Get-VMMemory -VMName $oldVM.name).Startup $switch = (Get-VMNetworkAdapter -VMName $oldVM.name).SwitchName New-VM -Name "VM01" -Generation $oldVM.Generation -MemoryStartupBytes $memory -SwitchName $switch ``` -------------------------------- ### New-VM Source: https://learn.microsoft.com/en-us/powershell/module/hyper-v/new-vm Creates a new virtual machine with specified parameters. ```APIDOC ## New-VM ### Description The `New-VM` cmdlet creates a new virtual machine on a Hyper-V host. ### Parameters - **Name** (String) - Required - The name of the new virtual machine. - **MemoryStartupBytes** (Byte) - Optional - The amount of memory to assign to the virtual machine at startup. - **NewVHDPath** (String) - Optional - The path for a new virtual hard disk. - **NewVHDSizeBytes** (Byte) - Optional - The size of the new virtual hard disk. - **VHDPath** (String) - Optional - The path to an existing virtual hard disk. - **ComputerName** (String) - Optional - The name of the host server where the VM will be created. - **Credential** (PSCredential) - Optional - Credentials for the remote host. - **Generation** (Int) - Optional - The generation of the virtual machine (1 or 2). - **BootDevice** (String) - Optional - The device to boot from (e.g., CD). - **NoVHD** (Switch) - Optional - Indicates that the virtual machine should be created without any VHD disks. - **SwitchName** (String) - Optional - The name of the virtual switch to connect to. ### Examples ```powershell New-VM -Name "VM01" -MemoryStartupBytes 512MB ``` ```powershell New-VM -Name "VM01" -MemoryStartupBytes 1GB -NewVHDPath D:\vhd\base.vhdx -NewVHDSizeBytes 40GB ``` ```powershell New-VM -Name "VM01" -MemoryStartupBytes 2GB -Credential (Get-Credential) -ComputerName HostServer01 ``` ```