Sergey Nivens - Fotolia

Tip

Top 5 SCVMM PowerShell commands

Manually making changes to Hyper-V hosts and VMs is very time-consuming. Manage System Center Virtual Machine Manager with PowerShell commands to make administration easier.

IT administrators who want to make management with Microsoft's System Center Virtual Machine Manager more efficient can use these top five SCVMM PowerShell commands to validate hosts and Run As accounts, remove orphaned hosts, and more.

Microsoft designed System Center Virtual Machine Manager (SCVMM) to help organizations manage entire virtualization stacks with ease. SCVMM admins can manage operations with the SCVMM GUI or PowerShell.

PowerShell offers greater flexibility and enables admins to perform repetitive tasks quickly, which reduces the time it takes to perform the same tasks with SCVMM. Save time with these top five SCVMM PowerShell commands.

1. Validate Hyper-V hosts with SCVMM PowerShell commands

SCVMM admins must validate Hyper-V hosts before implementing a service or role on them. For example, before installing the failover cluster feature on Hyper-V hosts, admins must check that the identified Hyper-V hosts are capable of promotion to a cluster.

Admins can easily find out if Hyper-V hosts are ready to accept failover cluster roles by using the SCVMM PowerShell commands below. This example assumes there are Hyper-V hosts that reside in an SCVMM Host group called Seattle.

$VMMHostGroup = Get-SCVMHostGroup -Name "Seattle"

$AllNodesInGroup = Get-SCVMHost

$AllResults = Test-SCVMHostCluster -VMHost $AllNodesInGroup

$AllResults.ValidationResultPS

In the above commands, the Test-SCVMHostCluster SCVMM PowerShell cmdlet checks if the Hyper-V hosts are ready for a promotion to a cluster. The results reside in the ValidationResultPS property and the output displays on the screen. If admins must see the location of the file, they can execute $AllResults.ResultFileLocation.

2. Validate Run As accounts

Before admins execute any major tasks in SCVMM, they must validate Run As accounts because SCVMM uses Run As accounts to perform actions on the destination Hyper-V hosts. This is necessary when deploying failover clusters on Hyper-V hosts, deploying VMs on Hyper-V hosts and deploying service templates.

The SCVMM PowerShell cmdlet Test-SCDomainCredential performs a quick check for a Run As account, which the example below demonstrates:

$ThisRunAsAccount = Get-Credential

$TestThisAccount = Test-SCDomainCredential -Credential $ThisRunAsAccount

If the commands above successfully verify the Run As account credentials, an approved message will display in the PowerShell window.

3. Quickly get the status of all VMs that SCVMM manages

Admins might want to check the status of all the VMs that SCVMM manages every day to ensure they are all in the expected state.

On an SCVMM host, the below SCVMM PowerShell command produces a list of all the VMs that SCVMM manages and their statuses:

Get-VM * | Format-Table ComputerNameString, Status -Auto

4. Remove a Hyper-V host from SCVMM

If admins recently reinstalled a Hyper-V host before removing it from the SCVMM server, the status of the Hyper-V host displays as Pending in the SCVMM console. Trying to remove the Hyper-V host from SCVMM produces an error that indicates the Hyper-V host is no longer available.

In some cases, the remove action in the right-click context menu will be gray. SCVMM PowerShell commands come in handy here.

The below SCVMM PowerShell commands successfully remove an orphaned Hyper-V host.

$ThisHyper-VHost = "PRDHyperV1"

Get-SCVMHost $ThisHyper-VHost | Remove-SCVMHost -Force

The use of the -Force switch in the above command clears all the entries that pertain to the target Hyper-V host from SCVMM. Similar to the orphaned Hyper-V host process, admins can remove an orphaned VM from the SCVMM database with another SCVMM PowerShell command.

Get-VM -VMServer "VMMHost1" -Name "VirtualMachineName" | Remove-VM -Force

5. List ISO files that VMs have mounted in SCVMM

If admins have hundreds of VMs that SCVMM manages, checking which VMs have ISO files mounted can take a considerable amount of time with SCVMM. The below SCVMM PowerShell commands list the names of the VMs and the ISO files the VMs have mounted.

$ThisVMServer = "PRODVMServer"

Get-VirtualDVDDrive -VMServer $ThisVMServer -All | Where-Object {$_.ISO -ne $null) | Select-Object Name, ISO

With these five SCVMM PowerShell commands, admins can make light work of some of the most strenuous SCVMM tasks.

Dig Deeper on IT systems management and monitoring

Software Quality
App Architecture
Cloud Computing
SearchAWS
TheServerSide.com
Data Center
Close