PowerShell to the rescue when counting seminar attendees in Outlook

My company is going to host a seminar this thursday on Microsoft Sweden in the subject of Switch To Hyper-V.

Today I got the registrations from the guy receiving them from the company webpage. Every registration that is done results in a mail (yes I know! it is so old fashioned!!) Here is an example mail msg:

Screen Shot 2013-09-30 at 21.08.55

So to collect the info about the attendees and the information I used PowerShell.

on ScriptingGuys page I found their massage of Outlook and I added Attachment and Body objects to it.

Screen Shot 2013-09-30 at 20.55.52

And then as every mail was sent from the admin-guy as an attachment I had to save them to a local directory and from there do the extraction. It would have been easy to do the save for all just in Outlook if not all of  the emails had the same name!!

Screen Shot 2013-09-30 at 17.03.44

To fix that I used PowerShell again

Screen Shot 2013-09-30 at 20.48.52

And here is my script to get the attendees objects out

if you do have the mails in the inbox and not as an attachements you could use $switch.Body instead of saving them and using Get-Item 🙂

New PowerShell VM Inventory Script for SCVMM 2012 SP1/R2

about 1 1/2 years ago I made a script for Inventory Reporting in SCVMM 2012 and now I have been working on an update that supports VMM 2012 Sp1 and R2, there have been some changes in the cmdlets so now it was time to refresh it and add some information.

In VMM 2012 R2 the possibility to get the IP address has been added so I utilize that from VMM, if you are using the SP1 version I can get the IP address from the Hyper-V PowerShell module and the cmdlet Get-VMNetworkadapter, that works only on Hyper-V 2012 Hosts and the Integration components have to be updated. The function reports the number of NIC´s and VHD´s but not show all, I have chosen to just add one virtual NIC and three virtual hard disks in this, that can be altered if you want and just add in the hash table.

In this new function I have added a switch parameter that lets you select if you want a html/csv report or just work with the objects that comes out of it when running 🙂

To use it you can just use one of several ways with parameters

Screen Shot 2013-09-29 at 22.38.05

 

And here is the script function

And here is an example of the csv report, and yes it is much info, the CSV can be scrolled quite a bit 🙂

Screen Shot 2013-09-29 at 22.27.45

You can select what you want included in the report by just using the function and pipe it to Export-CSV

 

 

Migration script for VM´s moving to Hyper-v 2012 from 2008r2 with VMM

As you might have been reading on my blog about the implementation of the SCVMM 2012 SP1 I have been doing at a customer and the challenges with networking and hosts.

Now the turn has come to migrate those VM´s that reside on the old 2008 R2 cluster to the new shiny Hyper-V 2012 cluster. The approach this time has been to use the VMM and migrate them between the clusters.

VMM 2012 SP1 has some shortcomings when it comes to different configured clusters and their networks. With a bit of crafty PowerShelling I solved that.

So the error was that I could not set the network that I wanted in the migration on the target.. In the VMM Console I get a error and could not continue :

Screen Shot 2013-09-26 at 09.47.36

Then I thought that its maybe an issue in the GUI and can be override in the PowerShell console but NOOOO there exist no parameter for setting the virtual switch 🙁

Screen Shot 2013-09-26 at 09.44.49

So I wrote a little script function that first get the VLAN information on the network adapters connected on the VM and then disconnects the virtual network adapters for the VM before migration and then the migration succeeds  🙂 and after the migration I connect the virtual network adapters to the VM networks on the new logic switch that correlates to the right VLAN from the source.

from a previous bad experience when trying to migrate VM´s between versions of Hyper-V on VMM with snapshots (Checkpoints) I added a check in the function to not allow migration of VM´s that have active snapshots.

Screen Shot 2013-09-26 at 14.28.54

And here is the script (will do some more thorough testing and add some functionallity but it gives you the idea )

 

When to select SC Orchestrator over vCenter Orchestrator

vsorch

I got a question from a customer why they should choose System Center Orchestrator instead of vCenter Orchestrator.

Both products work in the automation field and can do quite much, as they both are extendable and you can develop add-ons, the possibilities are almost endless!

In the case of the System Center Orchestrator, it is included in the System Center suite so if you already use some of the components  and have the licenses in place then you can start automating a lot more.

In the case of vCenter Orchestrator, it is included in the vCenter license that you buy in your vSphere suite.

Both orchestrators are very easy to start working with as they are gui based. the vCenter Orchestrator integrates into the vSphere client and from there you can easily start the wanted workflow. With both you can create workflows/runbooks and let users connect to a web console to kick of the action.

Example of a runbook from SCO

exempeluseradd

Example of a workflow from vCO

Screen Shot 2013-09-26 at 09.53.23

In both there are possibilities to automate for example Active Directory and users. Onboarding processes when new employees start is an example of an process that often involves quite some manual intervention and benefits from automation. Giving end users and system owners the possibility to create and manage their own virtual machines through a web portal is another example that would offload the IT departments technicians busy day. The list of examples goes on and on…

System Center Orchestrator Architectural overview:

Screen Shot 2013-09-25 at 21.49.06

vCenter Orchestrator Architectural overview:

Screen Shot 2013-09-25 at 21.39.22

Comparison table:

SCO VCO
Licensing License required only for endpoints being managed.
No additional System Center licenses are needed for management servers or SQL Server technology.
vCenter standard license, no extra cost
Web console Yes Yes
Third Party Plugin/IP Yes Yes
Custom Plugin/IP development Yes Yes
Manage VMware vSphere Yes Yes
Manage System Center Yes No (not out of the box,requires quite a bit of customization)
Workflow/Runbook templates No Yes
Import/Export Workflow/Runbooks Yes Yes

 Conclusion

 So what orchestrator should you go with? Well it depends of course and here is my opinions,

If you have a VMware environment but run mostly Windows Servers and Microsoft applications and already have one or more System Center roles deployed the favor is in the SCO hand as SCO integrates so well with the Microsoft software using the supported Integration Packs and you also can with the VMware IP manage the vSphere environment. The rich amount of activities that the Integration Packs consists of makes it easy to start automating and quickly expand the scope and get some serious automation results in the whole stack! The SCO community helps you a lot when creating runbooks and that with the possibility to import a whole set of runbooks from other IT Pro´s can get your automation goal to be achieved quickly.

If you have a VMware environment and do not use any System Center roles and also have a more diverse load of VM´s with different operating systems, but still want to start automating your environment I would recommend the vCO. One big advantage that the vCO has is that it comes with a wide range of workflows already created and ready to be customized which helps you in the speed to automate.

From a licensing perspective it should be noted that as described in the table, you must have a System Center license on every physical device you plan to automate with System Center Orchestrator. On the virtualization hosts you would use the Windows Datacenter and System Center Datacenter licenses that gives you unlimited VM´s that you can manage. On single physical hosts you must use a System Center Standard license, but as I said above, if you already have another System Center Role you probably have the licensing in place :-). vCenter Orchestrator comes with the vCenter license and there is no extra licensing cost for managing single hosts or Active Directory.

Adding old 2008 R2 Hyper-V Cluster to SCVMM 2012 SP1

At a customer I have been deploying a new System Center Virtual Machine Manager 2012 Sp1.

I was here and deployed their previous solution with VMM 2012 and BareMetal deploy of their hosts. They have been patching and updating the hosts with the integration of wsus in VMM. As I described in an earlier post my first intention was to upgrade the database but after some investigation and trials I decided to start fresh instead…

So with the new installation I wanted to add the old Hyper-V cluster and manage it from the VMM 2012 SP1 and also be able to do migration from the old bare metal deployed hosts and cluster to the new cluster.

After adding the 2008 r2 cluster I had two nodes that did not respond correctly and with the following error

Screen Shot 2013-09-24 at 11.18.17

I tried to restart the VMM-agent on the hosts and that did not help, also tried to reboot the servers, which did not help either.

On one node I also tried to uninstall the VMM agent on the host itself and then to get it back into VMM involved some VMM-database massage, and that did not help either.

So what did help?!

Rebuilding the performance counters as this KB2554336 describes

To rebuild all Performance counters including extensible and third-party counters, type the following commands at an Administrative command prompt. Press ENTER after each command.

Rebuilding the counters:
     cd c:\windows\system32
     lodctr /R
     cd c:\windows\sysWOW64
     lodctr /R

Resyncing the counters with Windows Management Instrumentation (WMI):
     WINMGMT.EXE /RESYNCPERF

Stop and restart the Performance Logs and Alerts service. 
Stop and restart the Windows Management Instrumentation service.

and then restart the VMM agent did solve the above issue and now the hosts reports nicely in VMM

Screen Shot 2013-09-24 at 11.02.45

The hosts had been reporting correctly in the old VMM 2012 so what caused the per counters to go bad, maybe the installation of the new VMM 2012 SP1 agent? If you have had the same issues, please comment this post and share your thoughts!

Updated Add-SCNetworks function for virtual Networks in SCVMM 2012 SP1

Yesterday I described how I could get the networking info out from the VMM before a reinstall or if for another reason you need to get all networks defined.

In an earlier post I described my add networks script and now I have extended it a bit. I have this week made a function of it and also I have changed the import file format to fit the export-file as you get with the earlier post mentioned above. In the function I create a logic network if it is not already in place, that is also done for the network site in the logic network. The logic network created utilize VLAN.

So If you create or export a file with the following columns, Name, Subnet,VlanID you are going to success.

Screen Shot 2013-09-21 at 18.00.22

And when running the function:

Screen Shot 2013-09-21 at 18.05.13

One thing that I wanted also was the possibilty to create just one network with the script and that has also been added.

Screen Shot 2013-09-21 at 18.07.10

The function also handles if you already had setup a network with the same subnet and gives you a warning and do not create that net (maybe you accidentally try to add the same net twice and that is being handled)

Screen Shot 2013-09-21 at 18.11.55

Here is the function

# Add Networks to VMM 
#
# Niklas Åkerlund 2013-09-16
<#
.Synopsis
   Add networks to the logical network and creates virtual networks to them
.DESCRIPTION
   this function can take either a csv file as input for creating virtual networks
.EXAMPLE
   Add-SCNetworks -importfile .\networks.csv
.EXAMPLE
   Add-SCNetworks -Name DMZ -Subnet 192.168.10.0/24 -VlanID 100 -VMHostGroup DMZHosts
.Notes
Niklas Akerlund 2013-09-16
#>
function Add-SCNetworks
{
    [CmdletBinding()]
    Param
    (
        # Logical Network Name
        [Parameter(Position=0)]
        $LogicalNetworkName = "LumaNets",
        
        [Parameter(ValueFromPipelineByPropertyName=$true)]
        [Microsoft.SystemCenter.VirtualMachineManager.LogicalNetwork]
        $LogicalNetwork,

        # Network site name
        [string]
        $LogicalNetDefName="VMnets",
        
        # CSV file to be imported
        [string]
        $ImportFile = " ",

        # Name of the VM network
        $Name,
        
        $Subnet,
        
        $VlanId,
        
        $VMHostGroup= "All Hosts"

    )

    Process
    {
        
    if(!$LogicalNetwork){
        $LogicalNet = Get-SCLogicalNetwork -Name $LogicalNetworkName
        # If the logical network not exist, create it
        if(!$LogicalNet){
            $logicalNet = New-SCLogicalNetwork -Name $LogicalNetworkName -LogicalNetworkDefinitionIsolation $true -EnableNetworkVirtualization $false -UseGRE $false -IsPVLAN $false
        }
        Write-Verbose $LogicalNet.Name
    }else{
        $LogicalNet = $LogicalNetwork
    }

    $allSubnetVlan = @()

    # The networks that is going to be imported
    if ($ImportFile -ne " "){
        $vlans = import-csv $ImportFile -Delimiter ";"
       

        foreach ($vlan in $vlans) {
            # Check that the actual network not already is configured
            if(!((Get-SCLogicalNetworkDefinition).SubnetVLans.Subnet -contains $vlan.Subnet)){

                # First in fabric 
                $LogicalNetDef = Get-SCLogicalNetworkDefinition -LogicalNetwork $LogicalNet -Name $LogicalNetDefName
                $allSubnetVlan = $LogicalNetDef.SubnetVLans    
                $Subnet = $vlan.Subnet 
                Write-Verbose $Subnet
                $SubnetVlan = New-SCSubnetVLan -Subnet $Subnet -VLanID $vlan.VlanID
                $allSubnetVlan += $SubnetVLAN
                if($LogicalNetDef){
                    Set-SCLogicalNetworkDefinition -LogicalNetworkDefinition $LogicalNetDef -SubnetVLan $allSubnetVlan
                }else {
                    $LogicalNetDef= New-SCLogicalNetworkDefinition -LogicalNetwork $LogicalNet -Name $LogicalNetDefName -SubnetVLan $allSubnetVlan -VMHostGroup $VMHostGroup
                }

                # Then create VM Networks
                $vmNetwork = New-SCVMNetwork -Name $vlan.Name -LogicalNetwork $LogicalNet -IsolationType "VLANNetwork"
                #$vmSubnet = 
                New-SCVMSubnet -Name $vlan.Name -LogicalNetworkDefinition $LogicalNetDef -SubnetVLan $SubnetVLAN -VMNetwork $vmNetwork
            }else{
                Write-Host "Subnet $Subnet already exists" -ForegroundColor Red
            }
        }
    }else{
        # add only a single network
            if(!((Get-SCLogicalNetworkDefinition).SubnetVLans.Subnet -contains $Subnet)){
            
                # First in fabric 
                $LogicalNetDef = Get-SCLogicalNetworkDefinition -LogicalNetwork $LogicalNet -Name $LogicalNetDefName
                $allSubnetVlan = $LogicalNetDef.SubnetVLans    
                #$Subnet = $IPnet + $Octet
                Write-Verbose $Subnet
                $SubnetVlan = New-SCSubnetVLan -Subnet $Subnet -VLanID $vlanId
                $allSubnetVlan += $SubnetVLAN
                if($LogicalNetDef){
                    Set-SCLogicalNetworkDefinition -LogicalNetworkDefinition $LogicalNetDef -SubnetVLan $allSubnetVlan
                }else {
                    New-SCLogicalNetworkDefinition -LogicalNetwork $LogicalNet -Name $LogicalNetDefName -SubnetVLan $allSubnetVlan -VMHostGroup $VMHostGroup
                }

                # Then create VM Networks
                $vmNetwork = New-SCVMNetwork -Name $Name -LogicalNetwork $LogicalNet -IsolationType "VLANNetwork"
                #$vmSubnet = 
                New-SCVMSubnet -Name $Name -LogicalNetworkDefinition $LogicalNetDef -SubnetVLan $SubnetVLAN -VMNetwork $vmNetwork
            }else{
                Write-Host "Subnet $Subnet already exists" -ForegroundColor Red
            }
    
    }
    }
}

It works on both VMM 2012 SP1 and VMM 2012 R2 (preview)

I have looked at Alvin Morales latest blog post about creating networks and will see if I can add some more functionality into my code later on, I think that using parameters instead is a better way. There is always improvements that can be done and the only problem is the time 😉

Report of Logical Networks in SCVMM 2012 SP1

After working with an implementation and upgrade from SCVMM 2012 to SCVMM 2012 SP1 I have been trying to mitigate the issues with the old database and that with the network changes that arrived in SP1 has not been the best way.

Now I have decided to reinstall the VMM database to get a fresh start :-). Yes I lose some history but at least I get a system that will probably work!

I still want to get all the network information that I had in the old db to be able to create new virtual networks with the same network information

Here is an simple PowerShell script that helped me in getting the info

# Easy report of Logical Networks and subnet sites with vlans
#
# Niklas Akerlund

# Import Module
Import-Module virtualmachinemanager

# all Logical network definitions
$LogicalNetsdef = Get-SCLogicalNetworkDefinition

Foreach ($def in $LogicalNetsdef){
    
    foreach ($SubnetVlan in $def.SubnetVLans){
        $data=[ordered]@{
                    LogicalNetworkName = $def.LogicalNetwork.Name
                    Name=$def.Name
                    Subnet=$SubnetVlan.Subnet
                    VlanID=$SubnetVlan.VLanID
                }
         $Obj=New-Object -TypeName PSObject -Property $data  
         Write-Output $Obj   
    }

}

And when running it I pipe the info to a csv export

Screen Shot 2013-09-20 at 10.29.31

And here is the csv file

Screen Shot 2013-09-20 at 10.54.21

Configure updates for Microsoft products in Windows Update

I have installed a new Windows 2012 Server for System Center VMM SP1 and when I wanted to check what updates that were applicable I found a small issue in the Windows Update and that when configuring it for receiving more updates than just for Windows. After installing the System Center Virtual Machine Manager I definitely want the UR3 for example and that is distributed via Windows update.

By default the setting is as the following screen dump, only Windows updates are being analysed and considered!

Screen Shot 2013-09-17 at 10.44.14

 

And when pressing the link “Find out more” I get a web page as the following and here you can see that the active-x plugin fails to load

Screen Shot 2013-09-17 at 10.47.11

So to fix this I add the url to trusted sites on IE

Screen Shot 2013-09-17 at 10.47.57

And now when I reload the web page I can agree to the terms of use

Screen Shot 2013-09-17 at 10.48.16

And once that is completed I now get updates for more than just Windows on my server 🙂

Screen Shot 2013-09-17 at 10.48.47

Adding multiple Windows hotfixes with wusa and PowerShell

Today I have been exploring a bit in patching  hyper-v hosts with windows updates and hotfixes and when we have a cluster we can use the CAU ( Cluster Aware Updating) that can help you in the process of getting those hotfixes on in a automated fashion but that does not work on single hosts..

In my blog post about checking the hosts for updates and hotfixes I also have added the functionality to download the hotfixes from Microsoft´s servers..

An easy way to add several hotfixes to a host is to use PowerShell with wusa (windows update standalone installer) and it eats .msu files gladly.

But wait, the hotfixes is in a self-extractor exe with at least for some no command-line way to automate, BAD!! So PowerShell to the rescue again, and here on this blog post I found a guy making a PS function to unzip an archive file and it works on the hotfix.EXE also!

Screen Shot 2013-09-13 at 20.18.45
Get-Item .\* | %{Expand-ZipFile -FilePath $_.FullName -OutputPath c:\hotfixes}

And then we can use the WUSA and that wrapped in a foreach with a little while loop to handle that not a  new wusa starts before the preceding one is done as it cannot be run several instances simultaneously (maybe there is a better way to do this of course but this works 😉 )

Screen Shot 2013-09-13 at 14.38.17
Get-Item c:\hotfixes\* | foreach {WUSA ""$_.FullName /quiet /norestart"";while(get-process wusa){Write-Host "Installing $_.Name"}}

And to see if your hotfixes has been installed you can use the following command

check-hotfixesinstalled
Get-HotFix | Where Description -match hotfix

(Get-HotFix | Where Description -match hotfix).count

and of course after installing the hotfixes we need to reboot 🙂

Upgrade Windows 8.1 preview to 8.1 RTM with some quirks

Today I wanted to upgrade my Windows 8.1 Preview to the RTM release as it was released yesterday 🙂

In the RTM version you cannot upgrade from the preview to RTM  and retain the installed apps without altering the magic cversion.ini file and I am a lazy guy and do not want to install all my apps again after installation ( or just curious to see if it works).

Screen Shot 2013-09-10 at 10.53.56

This is not a supported way of doing things of course, but it is possible.

So I edit the cversion.ini and change the build number to the preview version and voila the option to retain both apps,personal data and settings appear. The cversion.ini file is found under the Image\Sources.

Screen Shot 2013-09-10 at 10.13.58
Screen Shot 2013-09-10 at 10.15.34

And then the upgrade started..

Screen Shot 2013-09-10 at 10.16.41

Although after the installation finishes some application reinstallation occurs and my vpn client wants to be reinstalled with the new version..  well you cannot get everything 😛

Screen Shot 2013-09-10 at 10.35.16

Lync started directly after I logged in but when starting Outlook I had to restart the computer as you can see below and then it also worked nicely 🙂

Screen Shot 2013-09-10 at 10.36.55