Scripting. Powershell, VMware, Windows, Active Directory & Exchange. All that kind of stuff…..
RSS icon Email icon Home icon
  • Issue with PowerCLI: Not authenticated and session timeout

    Posted on March 15th, 2013 Jonathan Medd 1 comment

    A colleague of mine experienced this issue recently where after making a PowerCLI connection to a vCenter and instantly running a command such as Get-VM, he would be prompted by the error:

    
    Get-VM. Not authenticated. Possible cause of this error is that the connection was left unused for a while and session has timed out.
    
    

    Checking he was connected to a vCenter appeared to indicate that he was, i.e.

    
    $global:defaultVIServer
    
    

    returned a value. Seems like this may be an issue with PowerCLI 5.1 since other similar reports indicate reverting to 4.1 does not have the issue.

    We didn’t have that option, so in this instance took the recommendation to amend the PowerCLI timeout as follows, which seemed to help in our case:

    
    Set-PowerCLIConfiguration -WebOperationTimeoutSeconds -1
    
    
  • PowerCLI 101 at North East Bytes, Wed 20th March 2013

    Posted on February 21st, 2013 Jonathan Medd No comments

    While on my working sojourn up North my good friend and fellow PowerShell MVP Jonathan Noble asked me to present a PowerCLI 101 session for the North East Bytes User Group he helps to run. So on Wednesday 20th March you can join us for this event at Newcastle University, session abstract and sign up details are below:

    NEBytes March 2013 – Power The World With Imagination

    PowerCLI 101
    IT Pros are starting to come to grips with the idea of managing Microsoft products with PowerShell, but it’s not just Microsoft who are making use of the powerful automation capabilities on offer. VMware have been developing their own PowerShell-based management shell for some time – PowerCLI. In this session, Jonathan Medd, a Microsoft MVP for Windows PowerShell and VMware vEXPERT, will introduce PowerCLI and show you how to really take control of your virtual infrastructure.

  • Working with Custom Attributes in PowerCLI

    Posted on February 12th, 2013 Jonathan Medd No comments

    I recently had a need to create some custom attributes for Clusters and VMs in vCenter. Having previously done this a few times a while back in vCenter I fired up Set-CustomField in PowerCLI 5.1, but was greeted with the following message:

    
    $VM | Set-CustomField -Name "TestAttribute" -Value "True"
    WARNING: Use Set-CustomAttribute cmdlet.
    WARNING: The 'Set-CustomField' cmdlet is deprecated. Use the 'Set-CustomAttribute' cmdlet instead.
    
    

    So it would work fine now, but going forward some of my code would be deprecated and potentially not work when PowerCLI was upgraded, so I looked for what the options now were, but before we do a quick review of what Set-CustomField gave you.

    Having created the above, an additional column TestAttribute would be available in the vSphere client.

    and is also viewable on the VM summary page

    The additional TestAttribute column is also available in the vSphere web client:

    However, it is not available in the summary page of the VM (admittedly you can’t add them here via the GUI either, like you can in the C# client):

    In terms of accessing this data via PowerCLI there are a couple of ways to get at it:

    
    $VM | Get-Annotation
    
    $VM.CustomFields.Item("TestAttribute")
    
    

    These commands always seemed slightly strange in that there was no Get-CustomField cmdlet, Set-CustomField could create a new one and also to remove a custom attribute you needed to specify a single entity, selecting multiple would result in errors after the first one, e.g. Get-VM | Remove-CustomField would remove the custom field after the first VM, but then subsequently produce an error.

    
    $VM | Remove-CustomField -Name "TestAttribute"
    
    Get-Command *Field*
    
    

    So moving on, what is available now? Enter the Verb-Attribute cmdlets:

    
    Get-Command *Attribute*
    
    

    we now have a Get cmdlet, to access those already created.

    Now we must first create the custom attribute, then we can view created custom attributes with Get-CustomAttribute and set values with Set-Annotation

    
    New-CustomAttribute -TargetType "VirtualMachine" -Name "TestAttribute2"
    
    $VM | Set-Annotation -CustomAttribute "TestAttribute2" -Value "True"
    
    Get-CustomAttribute
    
    

    The data can be accessed the same way as before using PowerCLI

    
    $VM | Get-Annotation
    
    $VM.CustomFields.Item("TestAttribute")
    
    

    From a GUI perspective, the story is the same as before:

    We can now remove the custom attribute in a more typical PowerShell style:

    
    Get-CustomAttribute -Name "TestAttribute2" | Remove-CustomAttribute -Confirm:$false
    
    

    One thing to watch out for that tripped me up with this change was when I used New-CustomAttribute to create a custom attribute with multiple TargetTypes, e.g. Cluster,VirtualMachine. While this worked fine in my test environment using PowerCLI 5.1, when I ran the code in production to subsequently Set-Annotation on a new attribute it would fail with the issue detailed here. Turned out that the PowerCLI version in production was 5.0.

    
    Set-Annotation: The specified parameter 'CustomAttribute' expects a single value, but your name criteria 'TestAttribute' corresponds to multiple values
    
    

    It hasn’t been confirmed yet, but it looks like there is an issue with Set-Annotation in PowerCLI 5.0 that is fixed in 5.1.

  • Automation Station at the UKVMUG 2012

    Posted on November 13th, 2012 Jonathan Medd No comments

    How do you provision, manage and decommission your (sprawling) infrastructure? Running around fighting fires while interesting project work falls by the wayside? Spending long evenings and weekends carrying out maintenance tasks while others are tweeting pictures of what fun they’re having in their spare time? Hiding from the bosses while they hunt you down to deploy a private cloud before Friday afternoon? Or even just figuring out what the heck infrastructure you have got and what underlying issues can you report on…..

    Maybe you should consider some automation within your environment. If you’re coming to this year’s UKVMUG on November 15th in Birmingham then come visit Alan Renouf, William Lam and myself at the Automation Station, part of the extensive range of additional community content available at this already great event.

    From provisioning / decommissioning physical and virtual servers, users, storage, networking and applications, through maintenance tasks, workflows and software testing, to what tools such as PowerShell, PowerCLI, vSphere CLI, Orchestrator, Python etc, you should or could use for different scenarios. We’d love to hear what automation you are already carrying out in your environment and have an opportunity to discuss what other things you could do.

    If you ask nicely we might even write some code for you to take away to carry out an automation task.

    Look forward to seeing you there and also highly encourage you check out the other community content available on the day (times subject to change, but we’ll be around all day :-) )

  • Install PowerCLI 5.1 in Windows 8

    Posted on November 13th, 2012 Jonathan Medd 1 comment

    I don’t believe that PowerCLI 5.1 is yet officially supported on Windows 8, however that’s where I wanted to run it. While carrying out the installation I hit this issue, i.e. .NET Framework 2.0 was not installed as a pre-requisite. This is because PowerShell 3.0 on Windows 8 uses .NET 4 and no longer has .NET 2.0 as a requirement.

     

    To install .NET Framework 2.0 in Windows 8 you need to turn on .NET Framework 3.5 as an optional feature, this will include .NET Framework 2.0. You can view the current status of this feature with PowerShell (note: the Online parameter means ‘take the action on the OS currently running on the local computer’):

    
    Get-WindowsOptionalFeature -FeatureName netfx3 -Online
    
    

     

    To enable .NET Framework 3.5, 3.0 and 2.0 run:

    
    Enable-WindowsOptionalFeature -FeatureName netfx3 -source D:\sources\sxs -Online
    
    

    where source is the location of the Windows 8 media.

     

    The state of this optional feature has been updated:

    
    Get-WindowsOptionalFeature -FeatureName netfx3 -Online
    
    

    You can now complete the PowerCLI install.

    It is now possible to take advantage of some the cool features in PowerShell 3.0, such as intellisense in the ISE console which includes the installed PowerCLI cmdlets:

  • New Book: Building EUC Solutions with VMware View

    Posted on August 9th, 2012 Jonathan Medd No comments

    Fellow London VMUG regulars and vExperts Barry Coombs and Mike Laverick have recently self published a new title Building EUC Solutions with VMware View. This book covers the most recent release of View 5.1 and having been privileged to help review one of the chapters and already get myself 1/4 the way through the book it is looking to be a phenomenal effort.

    The authors have a lot of real world experience and translate this into the book. The amount of detail they go into is excellent and it isn’t just a VMware only book – there is good commentary of VDI design and other related considerations, no matter which solution in the market you are going for. For instance there is coverage on using an F5 appliance to load balance the View Security server, how to use storage integration from Dell, EMC and Netapp, and coverage of clients such as iPad, OS X and Teradici zero clients. They also cover some of the newer solutions from VMware such as virtualising your applications with ThinApp, Horizion Application Manager plus look into the future of applications over the next few years with things like projects Octopus and AppBlast.

    It was also good to see a chapter on managing View with PowerCLI.

    I’ve really enjoyed reading it so far and am looking forward to the rest of it. If you already work with View or are considering a deployment then I highly recommend putting this on your reading list.

    You can get yourself a copy over at Lulu. All profits go to Unicef, which is an excellent decision by the authors and another reason for you to go and grab a copy.

  • Vote VMworld Independent!

    Posted on May 29th, 2012 Jonathan Medd No comments

    The public vote for sessions at VMworld opened today and there are a crazy number of great sessions to choose to vote for. I decided to give it a go myself this year, so have teamed up with my good buddy Hal Rottenberg to put forward the session 2112 Transforming Your Automation Scripts with Advanced PowerShell / PowerCLI. If you would like to see us present it, then please consider voting it up!

    I’m always keen to promote other independent people who submit sessions, particularly from the UK, so I would like to highlight the following sessions also for your consideration:

    Mike Laverick (anyone who describes themself as an Elvis impersonator surely deserves a vote!):

    Luc Dekens - partnering with my good friend Alan Renouf

    Julian Wood:

    Darren Wollard:

    Tom Howarth:

    Brendon Higgins:

    Of course there are loads more I could mention, still trying to digest the options!

  • The Importance of Being On Time

    Posted on April 2nd, 2012 Jonathan Medd 3 comments

    In an Active Directory environment its typical for client machines to use a local domain controller as their time source, domain controllers with the PDC emulator for the domain and the PDC emulator for the root domain to synchronise time with an external source. In most circumstances the aim is to keep the time synchronised within a 5 minute tolerance level, this will ensure there are no issues with Kerberos authentication which has the 5 minute tolerance as part of its requirements.

    For some applications a tolerance of 5 minutes is too large and can cause issues with the application. You may need to adjust items such as the polling interval to ensure that the time is within a lower tolerance, but first of all you need to know how far out of tolerance the servers within your environment are.

    The below Get-WindowsTimeDifference function can help you out here. It will take a list of Windows computers as input and then compare their time to either a specified Time Server within the environment, or by default attempt to use the PDC emulator for the Root AD Domain (or failing that, the PDC emulator for the current domain). The default tolerance level is one minute, this can be altered with the ToleranceLevel parameter.

    A common cause of time sync issues can be Windows servers in the DMZ, which are not members of the domain. Consequently, by default they will not sync with a local domain controller and may need to be manually configured to use a time server (which doesn’t always happen!). Checking the time for these servers may require alternate credentials, so the Credential parameter is provided for that purpose.

    The example below demonstrates using a text file list of Windows Server names piped into Get-WindowsTimeDifference with one server out of synch when the ToleranceLevel has been set to 3 minutes.

    function Get-WindowsTimeDifference {
    <#
    .SYNOPSIS
    Get the time difference between a time server and Windows clients
    
    .DESCRIPTION
    Get the time difference between a time server and Windows clients
    
    .PARAMETER  ReferenceComputer
    Name of the computer to check time difference for
    
    .PARAMETER  TimeServer
    Name of a TimeServer to use instead of the PDC Emulator
    
    .PARAMETER  ToleranceLevel
    Amount in minutes to permit as an acceptable time difference. Default is 1
    
    .PARAMETER  Credential
    Supply a PSCredential to use alternative credentials for the WMI query
    
    .EXAMPLE
    PS C:\> Get-WindowsTimeDifference -ReferenceComputer Server01 -ToleranceLevel 2
    
    .EXAMPLE
    
    PS C:\> Get-Content servers.txt | Get-WindowsTimeDifference
    -TimeServer TimeServer -ToleranceLevel 3 | Select ComputerName,SynchronisedStatus,TimeDeviation,TimeServer
    
    .EXAMPLE
    PS C:\> Get-Content servers.txt | Get-WindowsTimeDifference -Credential (Get-Credential)
    
    .NOTES
    Author: Jonathan Medd
    Date: 16/03/2012
    #>
    
    [CmdletBinding()]
    param(
    [Parameter(Position=0,Mandatory=$true,HelpMessage="Name of the computer to check time difference for",
    ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$true)]
    [Alias('CN','__SERVER','IPAddress','Server','Computername')]
    [System.String]
    $ReferenceComputer = $env:COMPUTERNAME,
    
    [Parameter(Position=1)]
    [System.String]
    $TimeServer,
    
    [Parameter(Position=2)]
    [int]
    $ToleranceLevel = 1,
    
    [Parameter(Position=3)]
    [System.Management.Automation.PSCredential]
    $Credential
    )
    
    begin {
    
    # If no TimeServer specified, retrive the PDC Emulator for the Root Domain and the Current Domain
    if (-not($Timeserver)) {
    
    $Forest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
    $DomainContext = New-Object System.DirectoryServices.ActiveDirectory.DirectoryContext("Domain", $Forest.RootDomain)
    $RootPDCEmulator = ([System.DirectoryServices.ActiveDirectory.Domain]::GetDomain($DomainContext)).PdcRoleOwner.Name
    $CurrentDomainPDCEmulator = ([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()).PdcRoleOwner.Name
    
    # Attempt a WMI query to the PDC Emulator for the Root Domain
    try {
    
    $PDCEmulator = (Get-WmiObject Win32_OperatingSystem -ComputerName $RootPDCEmulator -ErrorAction Stop).__Server
    
    }
    
    # If there is an error (such as blocked TCP ports or permissions) try the PDC Emulator for the Current Domain instead
    catch [System.Exception] {
    
    $PDCEmulator = (Get-WmiObject Win32_OperatingSystem -ComputerName $CurrentDomainPDCEmulator).__Server
    }
    
    }
    }
    
    process {
    
    # If no TimeServer specified, calculate the time difference between the PDC Emulator and the Reference Computer
    if (-not($Timeserver)) {
    
    try {
    $PDCEmulatorWMI = Get-WmiObject Win32_OperatingSystem -ComputerName $PDCEmulator
    
    if ($Credential){
    
    $ReferenceComputerWMI = Get-WmiObject Win32_OperatingSystem -ComputerName $ReferenceComputer -Credential $Credential -ErrorAction Stop
    
    }
    
    else {
    
    $ReferenceComputerWMI = Get-WmiObject Win32_OperatingSystem -ComputerName $ReferenceComputer -ErrorAction Stop
    
    }
    
    $PDCEmulatorTime = $PDCEmulatorWMI.ConvertToDateTime($PDCEmulatorWMI.LocalDateTime)
    $ReferenceComputerTime = $ReferenceComputerWMI.ConvertToDateTime($ReferenceComputerWMI.LocalDateTime)
    $TimeDeviation = $PDCEmulatorTime - $ReferenceComputerTime
    }
    
    # Catch any errors with the WMI query to the Reference Computer
    catch [System.Exception] {
    
    $TimeDeviation = "Unable to contact server"
    
    }
    }
    
    else {
    
    # If TimeSever is specified, calculate the time difference between the TimeServer and the Reference Computer
    try {
    
    $TimeServerWMI = Get-WmiObject Win32_OperatingSystem -ComputerName $TimeServer
    
    if ($Credential){
    
    $ReferenceComputerWMI = Get-WmiObject Win32_OperatingSystem -ComputerName $ReferenceComputer -Credential $Credential -ErrorAction Stop
    
    }
    
    else {
    
    $ReferenceComputerWMI = Get-WmiObject Win32_OperatingSystem -ComputerName $ReferenceComputer -ErrorAction Stop
    
    }
    
    $TimeServerTime = $TimeServerWMI.ConvertToDateTime($TimeServerWMI.LocalDateTime)
    $ReferenceComputerTime = $ReferenceComputerWMI.ConvertToDateTime($ReferenceComputerWMI.LocalDateTime)
    $TimeDeviation = $TimeServerTime - $ReferenceComputerTime
    
    }
    
    # Catch any errors with the WMI query to the Reference Computer
    catch [System.Exception] {
    
    $TimeDeviation = "Unable to contact server"
    
    }
    
    }
    # Use the TimeDeviation variable to determine SynchronisedStatus and TimeDeviation to report
    if ($TimeDeviation -eq "Unable to contact server"){
    
    $SynchronisedStatus = "Unable to contact server"
    
    }
    
    elseif ([Math]::Abs(($TimeDeviation).Minutes) -ge $ToleranceLevel) {
    
    $SynchronisedStatus = "Not Synchronised"
    $TimeDeviation = [string]$TimeDeviation.Minutes +" Minute(s) " + [string]$TimeDeviation.Seconds +" Seconds"
    }
    
    else {
    
    $SynchronisedStatus = "Synchronised"
    $TimeDeviation = [string]$TimeDeviation.Minutes +" Minute(s) " + [string]$TimeDeviation.Seconds +" Seconds"
    }
    
    # Create custom objects to store the results
    New-Object -TypeName PSObject -Property @{
    ComputerName = $ReferenceComputer
    SynchronisedStatus = $SynchronisedStatus
    TimeDeviation = $TimeDeviation
    TimeServer = if ($PDCEmulator) {$PDCEmulator} else {$TimeServer}
    
    }
    }
    
    }
    
    

    It may also be important to prove that time is synchronised across your VMware servers. The Get-ESXTimeDifference function will do this for you. In the below example a list of VMware servers is obtained froma text file and the time checked against the Root Domain PDC emulator using the default ToleranceLevel of 1 minute.

    Note: Get-ESXTimeDifference requires PowerCLI installed and a connection to vCenter having already been made.

    
    function Get-ESXTimeDifference {
    <#
    .SYNOPSIS
    Get the time difference between a time server and ESX clients
    
    .DESCRIPTION
    Get the time difference between a time server and ESX clients
    
    .PARAMETER  ReferenceComputer
    Name of the computer to check time difference for
    
    .PARAMETER  TimeServer
    Name of a TimeServer to use instead of the PDC Emulator
    
    .PARAMETER  ToleranceLevel
    Amount in minutes to permit as an acceptable time difference. Default is 1
    
    .EXAMPLE
    PS C:\> Get-ESXTimeDifference -ReferenceComputer ESX01 -ToleranceLevel 2
    
    .EXAMPLE
    
    PS C:\> Get-VMHost ESX01 | Get-ESXTimeDifference
    -TimeServer TimeServer -ToleranceLevel 3 | Select ComputerName,SynchronisedStatus,TimeDeviation,TimeServer
    
    .NOTES
    Author: Jonathan Medd
    Date: 16/03/2012
    #>
    
    [CmdletBinding()]
    param(
    [Parameter(Position=0,Mandatory=$true,HelpMessage="Name of the computer to check time difference for",
    ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$true)]
    [Alias('CN','__SERVER','IPAddress','Server','Computername','VMHost','Name')]
    [System.String]
    $ReferenceComputer,
    
    [Parameter(Position=1)]
    [System.String]
    $TimeServer,
    
    [Parameter(Position=2)]
    [int]
    $ToleranceLevel = 1
    )
    
    begin {
    
    # If no TimeServer specified, retrive the PDC Emulator for the Root Domain and the Current Domain
    if (-not($Timeserver)) {
    
    $Forest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
    $DomainContext = New-Object System.DirectoryServices.ActiveDirectory.DirectoryContext("Domain", $Forest.RootDomain)
    $RootPDCEmulator = ([System.DirectoryServices.ActiveDirectory.Domain]::GetDomain($DomainContext)).PdcRoleOwner.Name
    $CurrentDomainPDCEmulator = ([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()).PdcRoleOwner.Name
    
    # Attempt a WMI query to the PDC Emulator for the Root Domain
    try {
    
    $PDCEmulator = (Get-WmiObject Win32_OperatingSystem -ComputerName $RootPDCEmulator -ErrorAction Stop).__Server
    
    }
    
    # If there is an error (such as blocked TCP ports or permissions) try the PDC Emulator for the Current Domain instead
    catch [System.Exception] {
    
    $PDCEmulator = (Get-WmiObject Win32_OperatingSystem -ComputerName $CurrentDomainPDCEmulator).__Server
    }
    
    }
    }
    
    process {
    
    # If no TimeServer specified, calculate the time difference between the PDC Emulator and the Reference Computer
    if (-not($Timeserver)) {
    
    $PDCEmulatorWMI = Get-WmiObject Win32_OperatingSystem -ComputerName $PDCEmulator
    
    $PDCEmulatorTime = $PDCEmulatorWMI.ConvertToDateTime($PDCEmulatorWMI.LocalDateTime)
    
    $ReferenceComputerTime = ((Get-View ((Get-VMHost $ReferenceComputer).ExtensionData.ConfigManager.DateTimeSystem)).QueryDateTime()).ToLocalTime()
    $TimeDeviation = $PDCEmulatorTime - $ReferenceComputerTime
    
    }
    
    else {
    
    # If TimeSever is specified, calculate the time difference between the TimeServer and the Reference Computer
    
    $TimeServerWMI = Get-WmiObject Win32_OperatingSystem -ComputerName $TimeServer
    
    $TimeServerTime = $TimeServerWMI.ConvertToDateTime($TimeServerWMI.LocalDateTime)
    $ReferenceComputerTime = ((Get-View ((Get-VMHost $ReferenceComputer).ExtensionData.ConfigManager.DateTimeSystem)).QueryDateTime()).ToLocalTime()
    $TimeDeviation = $TimeServerTime - $ReferenceComputerTime
    
    }
    # Use the TimeDeviation variable to determine SynchronisedStatus and TimeDeviation to report
    
    if ([Math]::Abs(($TimeDeviation).Minutes) -ge $ToleranceLevel) {
    
    $SynchronisedStatus = "Not Synchronised"
    $TimeDeviation = [string]$TimeDeviation.Minutes +" Minute(s) " + [string]$TimeDeviation.Seconds +" Seconds"
    }
    
    else {
    
    $SynchronisedStatus = "Synchronised"
    $TimeDeviation = [string]$TimeDeviation.Minutes +" Minute(s) " + [string]$TimeDeviation.Seconds +" Seconds"
    }
    
    # Create custom objects to store the results
    New-Object -TypeName PSObject -Property @{
    ComputerName = $ReferenceComputer
    SynchronisedStatus = $SynchronisedStatus
    TimeDeviation = $TimeDeviation
    TimeServer = if ($PDCEmulator) {$PDCEmulator} else {$TimeServer}
    
    }
    }
    
    }
    
    
  • Which VMs restarted after a vSphere HA event?

    Posted on March 29th, 2012 Jonathan Medd 1 comment

    I experienced a vSphere HA event where VMs restarted on other hosts and I was requested by management to confirm which VMs had restarted. Details are stored within vCenter events, but trawling through those manually for multiple VMs would be pretty tedious. Enter of course, PowerCLI. The Get-VIEvent cmdlet enables you to search through the events, but to a certain extent it kind of helps if you know what you are looking for since there is so much information to look through.

    In the PowerCLI Book, we include a function, Get-VIEventType to return the different type of events that are available. By using this function we can search for an event that would match HA restarts.

    
    Get-VIEventType | Where-Object {$_.Description -like '*restarted*'} | Select-Object Name,Description
    
    

    So to find these events when can now run a query and filter out only those that match the VmRestartedOnAlternateHostEvent. In the initial Get-VIEvent query we can also reduce the scope of the search by using -Type Info since these events are not recorded as Warnings or Errors.

    
    Get-VIEvent -start (Get-Date).adddays(-1) -MaxSamples 5000 -Type Info | Where-Object {$_.gettype().Name -eq "VmRestartedOnAlternateHostEvent"} | Select-Object @{N='VM';E={($_ | Select -ExpandProperty VM).Name}},@{N='Host';E={($_ | Select -ExpandProperty SourceHost).Name}},CreatedTime
    
    

    Update:

    After putting this post together I noticed (after the report came through this morning) that this check is also included as part of vCheck, but implemented slightly differently. As always, there’s usually more than one way to get to the same end result.

    $Date = Get-Date
    $HAVMrestartold =5
    Get-VIEvent -maxsamples 100000 -Start ($Date).AddDays(-$HAVMrestartold) -type info | Where {$_.FullFormattedMessage -match "was restarted"} |select CreatedTime,FullFormattedMessage |sort CreatedTime -Descending
    
    

    Update 2:

    While testing out this post on vSphere 5 (the above was all vSphere 4.1) I discovered that there had been a few changes. Firstly, there are now two types listed

    
    Get-VIEventType | Where-Object {$_.Description -like '*restarted*'} | Select-Object Name,Description
    
    

    Some research led to the discovery that the VmRestartedonAlternateHostEvent was deprecated in vSphere 5.

    Consequently, the below no longer produced any results:

    
    Get-VIEvent -start (Get-Date).adddays(-1) -MaxSamples 5000 -Type Info | Where-Object {$_.gettype().Name -eq "VmRestartedOnAlternateHostEvent"} | Select-Object @{N='VM';E={($_ | Select -ExpandProperty VM).Name}},@{N='Host';E={($_ | Select -ExpandProperty SourceHost).Name}},CreatedTime
    
    

    It needed to be modified to:

    
    Get-VIEvent -start (Get-Date).adddays(-1) -MaxSamples 5000 | Where-Object {$_.eventtypeid -eq "com.vmware.vc.ha.VmRestartedByHAEvent"} | Select ObjectName,CreatedTime
    
    

    Also the vCheck method no longer worked:

    $Date = Get-Date
    $HAVMrestartold =5
    Get-VIEvent -maxsamples 100000 -Start ($Date).AddDays(-$HAVMrestartold) -type info | Where {$_.FullFormattedMessage -match "was restarted"} |select CreatedTime,FullFormattedMessage |sort CreatedTime -Descending
    
    

    and needed to be modified to the below since the text changed slightly and it was now also a warning event:

    $Date = Get-Date
    $HAVMrestartold =5
    Get-VIEvent -maxsamples 100000 -Start ($Date).AddDays(-$HAVMrestartold) -type warning | Where {$_.FullFormattedMessage -match "restarted"} |select CreatedTime,FullFormattedMessage |sort CreatedTime -Descending
    
    

  • Including the HP Offline Bundle as part of an upgrade to ESXi 4.1 U2

    Posted on March 6th, 2012 Jonathan Medd 1 comment

    If you’re running your vSphere deployment on HP kit then there’s a pretty good chance you use the HP Customized ISO Image for installation, for example this one for ESXi 4.1 U1. These customised images typically contain HP management tools and drivers and are great for saving time during the installation process. Naturally you will be upgrading ESXi at some point, but it’s important that you also keep the HP part up-to-date too. To accompany the release of ESXi 4.1 U2 there is a corresponding release of the HP Offline Bundle. The release notes for this version do not suggest any enhancements or bug fixes, only that it is the version that is supported with 4.1 U2.

    Once you have downloaded the HP Offline Bundle, it is possible to deploy it via a number of methods. The installation notes suggest installing with the vihostupdate utility, however in this post I’m going to show how it can be installed via vCenter Update Manager.

    1) First of all the HP Offline Bundle needs to be imported into the Update Manager Patch Repository. Navigate to the Patch Repositoy and select Import Patches.

    2. Enter the path to the HP Offline Bundle. (Note: the GUI does not display the full path, just the filename)

    3. The patches will then be uploaded to the Patch Repository.

    4. Finally, finish off the wizard.

    5. Once the HP Offline Bundle has been imported a Host Extension Patch Baseline needs to be created. Navigate to Baselines and Groups and create a new Baseline, with the type changed from the default Host Patch to Host Extension.

    6. Select the Extension to add to the Baseline. The best thing to do here is enter HP into the search box to reduce the number of items to choose from.

    7. On the final page confirm the HP Offline Bundle has been added.

    Alternatively, once the HP Offline Bundle has been uploaded into the Patch Repository, it’s much easier to create this baseline via the vCenter Update Manger PowerCLI cmdlets. :-)   Note that we need to use the Extension parameter since the baseline will be of type Host Extension.

    
    New-PatchBaseline -Name "HP Offline Bundle for ESXi 4.1 U2 " -Description "HP Offline Bundle for ESXi 4.1 U2" -IncludePatch (Get-Patch -SearchPhrase "HP ESXi 4.1 Bundle 1.2-25") -TargetType Host -Static -Extension
    
    

    The main advantage for me of deploying the HP Offline Bundle with Update Manager is that we can take advantage of Baseline Groups. As the name suggests Baseline Groups enable you to group together multiple and different types of baselines. Consequently in this instance we can place the ESXi and HP Offline Bundle upgrade into a Baseline Group and carry out the upgrade to 4.1 U2 in a single remediation task.

    There are similar upgrade packages for ESXi 5 from HP, so this process could also be used for that upgrade.