Read more on "Server OS Spotlight" »

Streamlining Admin Tasks with SCVMM PowerShell Commands

By Nirmal Sharma (Send Email)
Posted February 17, 2016

Before we delve into covering helpful PowerShell SCVMM cmdlets you can use in your daily operational tasks, it is imperative to understand that System Center Virtual Machine Manager uses its own set of PowerShell commands to interact with virtual machines, Hyper-V hosts, Virtual Machine Management Server, VMM Agents and SQL Server databases. Windows Server TutorialsIn other words, SCVMM doesn't use the PowerShell cmdlets that ship with the Hyper-V role.

For more information on Windows servers Partner Offers

Although there are numerous SCVMM PowerShell cmdlets available for use, today we're going to cover the PowerShell cmdlets you're most likely to find useful in your daily operational tasks. Let's take a closer look at the PowerShell cmdlets you can use to get information for or initiate an action on quickly.

Listing Library Shares Created on a VMM Server

The library shares created on a VMM contain library resources such as virtual hard disks, ISO files, etc. VMM does not impose any limitation over how many library shares you can create.

If you need to get a list of library shares from a VMM server and store the output in a properly formatted file such as a CSV file, you can execute the Get-SCLibraryShare PowerShell cmdlet. For example, to get all the library shares created on a VMM Server and then store the output in a CSV file, run the following command:

Get-SCLibraryShare -VMServer "VMMServer.ServerWatch.Local" | Export-CSV LibraryShare.CSV

This command collects all the library shares from the VMM Server specified in the -VMServer parameter and then stores the output in a CSV file named LibraryShare.CSV file.

Get a List of VM Templates Created in SCVMM

VMM provides the Get-SCVMTemplate PowerShell cmdlet that you can use to get a list of VM templates created in the VMM. To generate a list of VM templates and store the output in a CSV file, execute these two commands:

Get-SCVMTemplate -VMServer "ProdVServer.ServerWatch.Local" | Export-CSV VMTemplates.CSV

Get-SCVMTemplate -VMServer "ProdVServer.ServerWatch.Local" | Where {$_.Name - like "Windows 10"} | Export-CSV VMTemplates.CSV

The first command collects all VM templates created on a VMM Server, while the second command collects VM templates that start with "Windows 10." Both commands store the output in a CSV file named VMTemplates.CSV.

Backing Up a VMM Database

In order to back up a virtual machine manager database, you can execute the Backup-SCVMMServer PowerShell cmdlet. The Backup-SCVMMServer PowerShell cmdlet supports backing up a virtual machine manager database to a local or a network share as shown in the following commands:

Backup-SCVMMServer -VMServer "ProdVServer.ServerWatch.Local" "Path "E:\ProdVServerBackups"

Backup-SCVMMServer -VMServer " ProdVServer.ServerWatch.Local " "Path "\\FileServer1\ProdVServerBackups"

The first command backs up a VMM database on a local folder, while the second command backs up a VMM database on a network share ProdVServerBackups created on the FileServer1 computer.

Disabling RunAs Accounts

In case you need to disable a RunAs account quickly, you can use the following PowerShell commands on the VMM Server:

$RunAsAccountToDisable = Get-SCRunAsAccount -Name "Admin1"
Disable-SCRunAsAccount -RunAsAccount $RunAsAccountToDisable

Backing Up Service Templates

While the Backup-SCVMMServer PowerShell cmdlet helps you back up a VMM database as well as the Service Templates and its settings, if you wish to back up specific Service Templates, you can use the Export-SCTemplate PowerShell cmdlet as listed below:

$MyServiceTemplate = Get-SCServiceTemplate -Name "ProdServiceTemplate1"
Export-SCTemplate -ServiceTemplate $MyServiceTemplate -Path C:\BackupSTemplates -SettingsIncludePrivate -Overwrite

The first command gets the Service Template name and the second (Export-SCTemplate) exports the Service Template and its settings to the C:\BackupSTemplate folder. If you want to export all Service Templates created in VMM, run this command instead:

Get-SCServiceTemplate | Export-SCTemplate -Path C:\BackupSTemplates -SettingsIncludePrivate -Overwrite

Validating VMM RunAs Accounts

VMM uses RunAs accounts to communicate with VMM Agents running on the Hyper-V hosts, but if the VMM server is not able to connect to VMM Agent due to some issues with the RunAs account, you can verify the RunAs account credential by using the Test-SCDomainCredential PowerShell cmdlet as shown below:

$RunAsCreds = Get-Credential
Test-SCDomainCredential -Credential $RunAsCreds

The first command stores the RunAs credential in the $RunAsCreds variable and the second verifies the credential and returns either True or False.

Validating Hyper-V Hosts Before You Create a Failover Cluster

SCVMM supports deploying Hyper-V clusters via the VMM console. Before you deploy a Hyper-V cluster, it is necessary that you run a pre-check to ensure a Hyper-V cluster can be deployed successfully. VMM offers PowerShell cmdlets for validating Hyper-V hosts before you create a Hyper-V cluster. All you need to do is run a series of commands as listed below:

$ThisHostGroup = Get-SCVMHostGroup -Name "Dallas"
$MyNodes = Get-SCVMHost
$GetResults = Test-SCVMHostCluster -VMHost $MyNodes
Write-Output $GetResults.ValidationResultPS
Write-Output $GetResults.ResultFileLocation

The first command gets the VMM host group and stores the output in the $ThisHostGroup variable. The second command retrieves all the Hyper-V host names from the VMM host group and then stores the output in the $MyNodes variable.

The third and subsequent commands validate Hyper-V nodes and display the location of the result file. The report file contains the necessary details about the state of each Hyper-V host.

Nirmal Sharma is a MCSEx3, MCITP and Microsoft MVP in Directory Services. He specializes in directory services, Microsoft Azure, Failover clusters, Hyper-V, System Center and Exchange Servers, and has been involved with Microsoft technologies since 1994. In his spare time, he likes to help others and share some of his knowledge by writing tips and articles on various sites and contributing to Health Packs for ADHealthProf.ITDynamicPacks.Net solutions. Nirmal can be reached at nirmal_sharma@mvps.org.

Follow ServerWatch on Twitter and on Facebook

Page 1 of 1

Read more on "Server OS Spotlight" »

Comment and Contribute

Your name/nickname

Your email

(Maximum characters: 1200). You have characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date