All posts filed under: Scripting

Retrieve list of VMs excluded from SCVMM PRO/Dynamic Optimization

We can exclude VMs from SCVMM Performance and Resource Optimization (PRO) or Dynamic Optimization (DO). This is done at a VM level and there is no central place to see what all VMs are excluded from optimization. PowerShell to the rescue, of course. The Get-VM cmdlet in SCVMM module has a property called ExcludeFromPRO which tells us if a VM is excluded from PRO or DO. So, this is quite simple.

I will publish another post to show you where exactly this comes handy. Watch this space.

Set (or inject) guest network configuration from Hyper-V host (Windows Server 2012)

Those of you who work(ed) on VMware ESX and use PowerCLI for ESX management would have – at some point in time – used the Set-VMGuestNetworkInterface cmdlet to set the IP address configuration of guest OS from the vCenter host or where you have PowerCLI installed. This is quite useful when performing automated guest OS installs and you want to be able to accurately set IP information for different network interfaces in the guest. In Hyper-V in Server 2008 R2, there were no interfaces to achieve something like this. However, as I’d mentioned in an earlier post, the updated WMI namespace in Hyper-V in Server 2012 provides a way to set the guest IP information from Hyper-V host. In a previous post, I showed you how to retrieve Hyper-V guest network configuration information using the updated WMI classes. In this post, we shall see how we can set the guest network information. We will use the new WMI class in Server 2012 Hyper-V WMI namespace – Msvm_GuestNetworkAdapterConfiguration. Make a note that this works only when …

Get Hyper-V (Windows Server 2012) guest network configuration using WMI

If you have not seen this yet, the updated WMI namespace for Hyper-V role in Windows Server 2012 has some hidden gems. I love playing around with WMI and the changes in Hyper-V namespace had me thinking about new possibilities. Here is the first one in this series of posts on how you can extend Hyper-V management beyond what is available in the Hyper-V PowerShell module. In this post, I will show you a simple function to get the guest network configuration details using WMI. We use the Msvm_GuestNetworkAdapterConfiguration WMI class to achieve this.

In the above function, we are making use of the updated virtualization namespace root\virtualization\v2. In this function, we first get the virtual machine object:

Once we have the VM object, we retrieve the VM setting data which includes information on how many synthetic network adapters are attached, etc.

Since the above command gives us entire VM setting data and we are interested only in the synthetic adapter data, we filter this further to get only the synthetic adapters attached …

PoshUtils: Set (enable or disable) resource metering on clustered Hyper-V virtual machines

In Windows Server 2012 with Hyper-V role, we can enable VM resource metering to measure the utilization of four resource types (CPU, memory, network, and disk) of Hyper-V virtual machines. Once the resource metering is enabled, using Enable-VMResourceMetering, we can use Measure-VM cmdlet to retrieve the utilization of a VM. Now, there are Enable-VMResourceMetering and Disable-VMResourceMetering cmdlets to enable and disable resource metering on an individual VM (-VMName parameter) or a group of VM objects (-VM parameter). So, what is this clustered Hyper-V virtual machines I am referring to? Well, the two cmdlets I just mentioned aren’t cluster object aware. This means you cannot give these cmdlets a clustered group object and then enable or disable resource metering on those virtual machine objects. So, this is where the following function will help you. It takes the name of the Hyper-V cluster as an input and enable or disable VM resource metering on all the virtual machines in the given cluster. You may already know that the Get-VM cmdlet is cluster object aware. So, we can …

PoshUtils: Downloading SharePoint 2013 prerequisites for offline install

Okay, this is yet another post on downloading the SharePoint 2013 prerequisites for offline install. I am sure you have seen many and everyone has their own way. But I think none of those posts/scripts – at least the ones I read – don’t give you a unified way to download the prerequisites for all combinations of Windows Server OS and SQL Server versions. So, here is my take. The idea of this script is to use the features of PowerShell 3.0 such as Out-GridView and default parameter values to reduce the amount of code required. Note: The list of prerequisites I compiled here is what I perceived looking at technet documentation. Do let me know if I missed out anything or need to change something here. Let us see the code first.

In the above code, I am using a CSV file I compiled with all the SharePoint 2013 prerequisite information. This is the key here. You can download the CSV file here. Instead of a hash, I preferred to use a CSV file as …

Configuring anti-affinity for Hyper-V virtual machines

If you have worked on VMware, you might already be aware of a concept of DRS rules. Using DRS rules, we can create VM anti-affinity rules so that no two virtual machines hosting similar application roles run on the same ESX host. For example, when you have a virtualized SQL mirror or a virtualized SQL failover cluster, it is critical to separate the SQL virtual machines participating in the application group onto different ESX hosts. This is where we can use VMware DRS rules – “Separate Virtual Machines” rule to be specific.

PoshUtils: Get all mirrored SQL databases using PowerShell and SMO

I have been validating different aspects of SQL mirroring and in the process I wanted a quick and automated way to handle database mirroring functions. This includes listing all mirrored databases, failing over databases manually to a mirrored instance, etc. So, in the process, I created several small functions in PowerShell to achieve what I wanted. I will share these functions as a series of posts and eventually, will release a PoshUtils module. So, in today’s post, let us see how we can retrieve a list of all SQL databases that are mirrored. This function can work with both default and named instances. Also, this assumes that you are using Windows authentication. Let us see the function:

When you run the Get-MirroredDatabase function, it returns a list of all databases that are mirrored and all properties of each database. You can filter the output by selecting the properties you want.