The Next Step – Integration with SCVMM-V PowerShell Module Cmdlets - Microsoft Hyper-V PowerShell Automation (2015)

Microsoft Hyper-V PowerShell Automation (2015)

Chapter 5. The Next Step – Integration with SCVMM

The System Center Virtual Machine Manager (SCVMM) comes with several built-in PowerShell cmdlets that allow one to manage the Hyper-V environment, which is deployed at a very large scale. In this chapter, we will look at how to integrate our existing Hyper-V infrastructure with SCVMM, which is an enterprise-level Microsoft application that allows you to manage multiple Hyper-V environments and provides you with a single pane of glass management experience.

We have subdivided this chapter into two sections, which will give you an insight into the advantages of integration with SCVMM and also give you details on the PowerShell cmdlets that you will get after integration with SCVMM:

· Why integrate with SCVMM?

· The new PowerShell cmdlets after integration with SCVMM

Why integrate with SCVMM?

SCVMM 2012 R2 does not just manage virtual machines (VM) anymore. It does more than that and manages the entire virtualized data center, effectively managing the entire VM host lifecycle. SCVMM 2012 R2 can now communicate with bare metal machines with no installed operating system, execute bare metal virtualization, and manage and deploy Hyper-V clusters as well as talk directly to SAN storage. SCVMM allows you to manage an entire cloud—you can now abstract the host, storage, and networking into a unified pool of computing resources.

SCVMM has the ability to deploy the App-V server and deploy the virtualized applications to hosts as well as enabling the SQL server profiles to deploy customized database servers. App-V allows you to stream your applications and allows the administrator to provide software as a service. It can also be centrally managed via the App-V management console. SQL Server profiles in SCVMM allow you to create a profile to deploy a SQL Server instance on a virtual machine.

Overall, the SCVMM features can be categorized into fabrics and services and clouds:

· The fabric feature can be subcategorized into core fabric management, resource optimization, and infrastructure enhancements

· The services and clouds feature includes the cloud management features

Core fabric management

The core fabric management feature gives you the ability to manage all your hardware resources, which include bare metal provisioning and network and storage management. It also enables you to manage multiple hypervisors such as Hyper-V, VMware, and Citrix. Fabric management refers to managing all the features that are necessary to manage VMs. The core fabric management feature consists of three main subcomponents, which are the compute, network and storage resources:

· The compute resource: This resource allows one to manage multiple hypervisor platforms, server hardware such as iLO and IPMI, bare metal provisioning with cluster creation, and storage provisioning.

· The network resource: This resource allows one to define a logical network with VLANs and subnets per data center location, and assign IP and MAC addresses from pools. It also allows the automated provisioning of load balancers.

· The storage resource: This resource allows the infrastructure administrator to do storage provisioning and management using SMI-S, allows it to discover the storage-device-to-VM relationship and classify storage according to its capability. This also allows the administrator to discover and provide new LUNs and assign new storage using Hyper-V hosts and clusters, and also caters to rapid provisioning using LUN cloning.

Resource optimization

The resource optimization feature allows the infrastructure administrator to run his or her Hyper-V environment at optimal settings, which include selecting the right power settings for the Hyper-V hosts using core parking, PRO integration with System Center Operations Manager (SCOM), and also dynamic optimization to proactively monitor the load of the VMs across the cluster.

The Resource optimization feature can be subdivided into three main subcomponents, which are listed as follows:

· Placement: This uses the star rating technique to optimally place the VMs on the right hosts. SCVMM has more than 100 placement checks for placing the VMs. It also supports custom placement rules and also its private cloud aware.

· Dynamic optimization: The Dynamic optimization feature does not require the pro-pack and, hence, has no dependency on SCOM. This feature manages the cluster level workload balancing scheme for better VM performance, and it utilizes live VM migration to move VM workloads. Dynamic optimizations can be set on manual and automatic modes.

· Power optimization: This feature effectively monitors the server that is being utilized and can power off the server during low levels of resource utilization. The administrator has the control to define a power optimization policy. The Power optimization feature is internally dependent on dynamic optimization.

Infrastructure enhancements

The infrastructure enhancement feature includes the new feature of highly available (HA) VMM servers, update management, and also extensive PowerShell support. The infrastructure enhancements feature can be subdivided into three main subcomponents, which are PowerShell, HA VMM server, and update management:

· PowerShell: SCVMM 2012 R2 is fully PowerShell v3 compatible. It is easily discoverable and also supports backward compatibility with the SCVMM 2008 R2 scripting interface.

· HA VMM server: SCVMM 2012 R2 is cluster-aware and hence, supports high availability. This feature effectively eliminates VMM server as a single point of failure.

· Update management: The update management feature allows the administrator to update the cluster in an orchestrated manner. Administrators can define baselines and control the update life cycle, which includes on demand scan and remediation. This feature is fully integrated with Windows Server Update Services (WSUS).

Cloud management

Next, let's look at the features that come under cloud management. Cloud management allows the administrator to manage everything in a private cloud environment, which includes managing the network resources in private cloud and delegating self-service provisioning capabilities that allow to author deploy and manage the virtual machines in the private cloud.

The resource cloud management feature can be subdivided into two main subcomponents, which are the cloud capacity and capability profiles and delegation and quota.

· Cloud capacity and capability profiles: A cloud can host highly available VMs, allow the virtual machines to use dynamic and differencing disks, and also allow to enable network optimizations. It also allows you to dimension the VMs as per the cloud capacity, which includes setting the number of vCPUs, memory, storage, and the number of deployed VMs.

· Delegation and quota: SCVMM allows the administrator to define scopes. The scopes can be subdivided into three types including the everything scope. The everything scope cannot be modified and it can perform any administrative action. The everything scope is owned by the VMM administrator. Next, we have the scope set for host groups and clouds. This scope consists of the delegated and the read-only administrator. This scope allows us to set up fabric by configuring hosts, network, and storage. It allows us to create a cloud and assign it to self-service users. The final scope is the clouds-only scope. A self-service user forms a part of this scope. This scope allows us to deploy and manage VMs and services and also to author the templates. The quotas are set as per user limits.

I hope you have a good understanding on the effectiveness of using SCVMM 2012 R2 to manage a Hyper-V infrastructure. Next, let's look at the new PowerShell cmdlets that come with SCVMM 2012 R2.

PowerShell cmdlets in integration with SCVMM

System Center Virtual Machine Manager 2012 R2 has enormous PowerShell support. Every task that you can perform on the SCVMM console can also be performed using PowerShell. Also, there are some tasks in SCVMM that can only be performed using PowerShell.

There are two ways in which you can access the PowerShell console for SCVMM:

· The first technique is to launch it from the SCVMM console itself. Open the SCVMM console in administrator mode and click on the PowerShell icon in the GUI console. This will launch the PowerShell console with the imported virtualmachinemanagerPowerShell module:

PowerShell cmdlets in integration with SCVMM

· You can also import the virtualmachinemanager PowerShell module using the Import-module cmdlet. Launch the PowerShell console in an administrative mode and type the following command:

· Import-module virtualmachinemanager

This will import the cmdlets in the virtualmachinemanager module for administrative use. As you can see in the following screenshot, if I execute a Measure-Object cmdlet, PowerShell gives me 619 cmdlets that are available for Hyper-V infrastructure management:

PowerShell cmdlets in integration with SCVMM

New PowerShell cmdlets have been added to all features in SCVMM, which include networking, virtual machines, and cloud and storage management. So, let's look at some of these cmdlets and their examples:

· New-SCVirtualMachine: The New-SCVirtualMachine cmdlet allows you to create a new virtual machine. The virtual machine can be created either from a stopped virtual machine or a virtual machine template, which exists on a library host. It can also be created from a virtual hard disk (VHD) that contains third-party operating system.

The following sample code shows how you can create a highly available virtual machine:

# We create a Job guid here which is unique per virtual machine created using the below set of cmdlets.

$JobGuid = [System.Guid]::NewGuid().ToString()

# Here we give the name of the virtual machine.

$VMName = "HA_VM01"

# In the below set of cmdlets we create a virtual network adapter, virtual dvd drive, hardware profile and a disk drive for the virtual machine.

New-SCVirtualNetworkAdapter -JobGroup $JobGuid -PhysicalAddressType Dynamic -VLANEnabled $False

New-SCVirtualDVDDrive -JobGroup $JobGuid -Bus 1 -LUN 0

New-SCHardwareProfile -Owner "scvmm\admin" -Name "HWProfile" -CPUCount 1 -MemoryMB 512 -HighlyAvailable $True -NumLock $False -BootOrder "CD", "IdeHardDrive", "PxeBoot", "Floppy" -LimitCPUFunctionality

$False -JobGroup $JobGuid

New-SCVirtualDiskDrive -IDE -Bus 0 -LUN 0 -JobGroup $JobGuid -Size 40960 -Dynamic –Filename "HAV_M01_disk.vhd"

# Here we give the details of the virtual machine host on which this virtual machine will be created..

$VMHost = Get-SCVMHost | where {$_.Name -eq "Hyper-V01.admin.com"}

# Next we get the hardware profile and operating system which should be used for the virtual machine.

$HardwareProfile = Get-SCHardwareProfile | where {$_.Name -eq "HWProfile"}

$OperatingSystem = Get-SCOperatingSystem | where {$_.Name -eq "64-bit edition of Windows Server 2008 R2 Datacenter"}

# next using the above set of input parameters we will create the virtual machine.

New-SCVirtualMachine -Name $VMName -Description "" -VMMServer "scVMMServer.scvmm.com" –Owner "scvmm\admin" -VMHost $VMHost -Path "R:\" -HardwareProfile $HardwareProfile -JobGroup $JobGuid -OperatingSystem $OperatingSystem -RunAsynchronously -StartAction NeverAutoTurnOnVM -StopAction SaveVM

· New-SCCloud: The New-SCCloud cmdlet allows you to create a private cloud in VMM. This cannot be done using the Hyper-V PowerShell cmdlets.

The following sample code shows you how to create a private cloud using this cmdlet:

$Guid = [System.Guid]::NewGuid()

Set-SCCloud -JobGroup $Guid

$HostGroup = Get-SCVMHostGroup -Name "HostGroup02"

New-SCCloud -JobGroup $Guid -Name "Cloud02" -VMHostGroup $HostGroup -Description "This is a cloud for HostGroup02"

Summary

In this chapter, you learned the real integration scenario of using SCVMM to manage our Hyper-V infrastructure. In the next chapter, we will cover in detail how to troubleshoot Hyper-V environment issues using the best practice PowerShell cmdlets in Hyper-V.

Chapter 6. Troubleshooting Hyper-V Environment Issues and Best Practices Using PowerShell

In this chapter, we will look at how to troubleshoot your Hyper-V environment using PowerShell. We will also look at how you can use Best Practices Analyzer (BPA) for Hyper-V to troubleshoot the environment. We have subdivided this chapter into two main sections covering the strategies that can be used to troubleshoot the Hyper-V environment:

· Troubleshooting the Hyper-V environment using event log: In this section, we will explore the built-in cmdlets in Windows that can be used to troubleshoot and analyze the Hyper-V events that get registered in the Windows event logs.

· Troubleshooting the Hyper-V environment using BPA: In this section, we will explore the Hyper-V BPA model-based cmdlets in the best practices module, which will be used to troubleshoot and verify whether the Hyper-V environment runs as per the best practice guidelines set by Microsoft.

Troubleshooting the Hyper-V environment using the event log

The Hyper-V administrator can use the Get-EventLog cmdlet to get the events related to Hyper-V. Monitoring these events using the Event Viewer GUI is a very tedious task. The following screenshot shows a view of the event log in the Event Viewer GUI. Scrolling through these events is a tedious task, as there are a lot of system-related events that are not related to Hyper-V:

Troubleshooting the Hyper-V environment using the event log

The Get-EventLog cmdlet can be directed to filter only the events that are related to Hyper-V. To do this, open up a PowerShell prompt in administrative mode and run the following command:

Get-EventLog system -source *Hyper-V* -after "07/21/2014"

The preceding command will query for all events related to Hyper-V in the system event log that occurred after July 27, 2014. Once we execute the preceding command, we will get the output returned as follows:

Troubleshooting the Hyper-V environment using the event log

As you can see, I get all the required information filtered out from thousands of events that were registered in the event log. To make it simpler, the output from the preceding command can be used when executing the Out-GridView cmdlet to get a small GUI-based result. Type the following command in the PowerShell prompt to get the GUI-based result:

Get-EventLog system -source *Hyper-V* -after "07/21/2014" | Out-GridView

Just append the Out-Gridview cmdlet to the first cmdlet to get the result as shown in the next screenshot. As you can see in the following screenshot, I get a nice UI console for my results, which I can filter further by adding criteria:

Troubleshooting the Hyper-V environment using the event log

Hyper-V event logs can also be found at the application event log. These events have the vmic prefix on them. Run the following command in a PowerShell window and you will be able to see the Hyper-V-related event logs in the application event log:

Get-EventLog -LogName Application -Source vmic* -before "07/21/2014" | Out-GridView

The preceding command will query the application event log and get details of all the events for Hyper-V that happened before July 27, 2014 and contains vmic as the prefix in the source text. Another way would be to use the Export-Csv cmdlet instead to the Out-GridView cmdlet to save the output into a CSV file.

Troubleshooting the Hyper-V environment using BPA

The Hyper-V administrator can also use the BPA that is built in the Windows Server 2012 to test whether the Hyper-V environment is running as per the best practices guidelines set by Microsoft. Microsoft Hyper-V Best Practices Analyzer checks the current configuration set of Hyper-V against a list of recommended configurations and generates warnings and alerts when there are deviations. Microsoft Hyper-V Best Practices Analyzer will also provide solutions to correct the warnings.

There are a number of BPA models that are available from Microsoft. To select the right BPA model for Hyper-V; run the following cmdlet in a PowerShell prompt:

Get-BpaModel | Select Id

Once we execute the preceding command, we will get a list of all the BPA models that exist on the server, including the Hyper-V one:

Troubleshooting the Hyper-V environment using BPA

Once we get the correct BPA model for Hyper-V, we need to execute this BPA model against the server using the Invoke-BpaModel cmdlet. Execute the command shown in the following screenshot in a PowerShell prompt in administrative mode to invoke the Hyper-V BPA model against the server:

Troubleshooting the Hyper-V environment using BPA

Once the BPA model completes its execution against the server, we can get the results using the Get-BpaResult cmdlet:

Get-BpaResult Microsoft/Windows/Hyper-V | Group-Object severity

Troubleshooting the Hyper-V environment using BPA

As you can see in the preceding screenshot, we executed the Get-BpaResult cmdlet and grouped the output based on the severity and the result shows that we have 2 errors, 4 warnings, and 64 information messages.

Next, to filter out the BPA results to get only the errors in our Hyper-V environment, we need to execute the following command in the PowerShell prompt:

Get-BpaResult Microsoft/Windows/Hyper-V | ?{$_.severity -match "error"} | select modelid,source,category,title,problem,resolution

Troubleshooting the Hyper-V environment using BPA

The PowerShell community

PowerShell has great community support. The following section provides you with many useful links to the project page and forums:

· Homepage: http://msdn.microsoft.com/en-us/library/windows/desktop/

· Manual and documentation: http://technet.microsoft.com/library/

· Wiki: http://social.technet.microsoft.com/wiki/contents/

· Blog: http://blogs.msdn.com/b/powershell/

Summary

In this chapter, we covered how to troubleshoot Hyper-V environment issues using the best practice PowerShell cmdlets in Hyper-V. With the topics that we covered in this book, an administrator is expected to have a good understanding of using PowerShell to automate his or her administrative tasks for Hyper-V management.