vCheck 3.1 ?

Whooops, looks like I got a couple of things wrong and I also missed something out that a few people were asking for, You can call this a minor release. I think you should be able to change these yourselves as they are very straight forward and its not worth me re-issuing the script as you would have to change your preferences again which is actually more work !

Request:  Multiple NTP servers

I was asked in V2 if I could change the script to report on multiple ntp servers as some people use multiple time sources for their hosts, here is how you would do that… (I will add this to v4)

On line 62 you will set the current ntp server, it looks like this:

$ntpserver = ntp.MyDomain.com

To use multiple ntp servers add more that one entry separating with the pipe symbol as so:

$ntpserver = ntp1.MyDomain.com|ntp1.MyDomain.com|ntp3.MyDomain.com

Next go to line 809 which currently reads:

$NTPCheck = @($VMH |Where {$_.state-ne Disconnected} |Select Name, @{N=NTPServer;E={$_ |Get-VMHostNtpServer}}, @{N=ServiceRunning;E={(Get-VmHostService -VMHost $_ |Where-Object {$_.key-eq ntpd}).Running}} |Where {$_.ServiceRunning -eq $false -or $_.NTPServer -ne $ntpserver})

The only bit that needs changing is the bit at the end which currently says –ne just change this to –notmatch as below:

$NTPCheck = @($VMH |Where {$_.state-ne Disconnected} |Select Name, @{N=NTPServer;E={$_ |Get-VMHostNtpServer}}, @{N=ServiceRunning;E={(Get-VmHostService -VMHost $_ |Where-Object {$_.key-eq ntpd}).Running}} |Where {$_.ServiceRunning -eq $false -or $_.NTPServer -notmatch $ntpserver})

Error: VM Alarms not working

I forgot to change a variable back after testing something so the Host Alerts section doesn’t actually do anything as it try’s to enumerate a blank object, all you need to do for this one is to change line 872 from the following:

foreach ($VMView in $VMViews){

To the following:

foreach ($VMView in $FullVM){

Sorry for these issues, as I said I will include these fixes in v4 and try and not make any more !

18 thoughts on “vCheck 3.1 ?

  1. Benedikt

    Unable to read data from the transport connection
    Any Idea for this error.
    mbk

  2. Virtu-Al

    @virtualsj

    Either that or the Connect-viserver cmdlet will also take a credential object which you can create in a similar way to what i do for the windows one.

  3. virtualsj

    Alan,
    Thanks for the response. In that case I would probably have to encrypt the script. The credentials of the user running the scheduled task won’t have rights in vCenter.

  4. Virtu-Al

    @Virtualsj

    The cred file is just for accessing the windows side of the vCenter, it will not help if you are not running the script as a user with credentials to the vCenter itself, if this is the case you will need to adjust the connect-viserver statement in the script to add a -user and -password parameter.

  5. virtualsj

    Alan,
    Great script however even though the first time I run the script my “crd” file gets created. Subsequent running of the script still prompts me for my username and password.

  6. Nico

    Hi, Snapshot check is no more working since I have installed vmware data recovery.
    Do you have same issue ?
    How can I solve it ?
    Regards

  7. EXOCET19

    Alan, this script is one of the best.
    I wanted to ask if there is a way to have it run on a cluster level not across the entire VC?

  8. Pingback: Top 5 Planet V12n bloggers 2009 | VMvisor

  9. Harold

    Alan, still loving your script.
    I have added two sections you might want to consider.

    With VMware vCenter 4.0 we can now disable alarm actions per host.
    Very easy during installation or patching, to prevent alarm actions from firing.
    But it is also very easy to forget to enable the alarms again, after maintenance is done.

    Added 2 sections for Hosts and Cluster Alarm Actions:

    # —- Cluster Alarm Actions Disabled —-
    If ($ClusterAlarmDisabled){
    If ($vSphere -eq $true){
    Write-CustomOut “..Checking Cluster Alarm Actions status”
    $actions = $clusters | get-view | where {$_.AlarmActionsEnabled -eq $False} | Select Name, AlarmActionsEnabled
    $clusteralarmsactions = @()
    $clusteralarmsactions += $actions
    }

    If (($clusteralarmsactions | Measure-Object).count -gt 0) {
    $MyReport += Get-CustomHeader “1” “Cluster(s) with Alarm Actions Disabled”
    $MyReport += Get-HTMLTable $Clusteralarmsactions
    $MyReport += Get-CustomHeaderClose
    }
    }

    # —- Host Alarm Actions Disabled —-
    If ($HostAlarmDisabled){
    If ($vSphere -eq $true){
    Write-CustomOut “..Checking Host Alarm Actions status”
    $actions = $VMH | get-view | where {$_.AlarmActionsEnabled -eq $False} | Select Name, @{N=”Cluster”;E={get-vmhost -name $_.name | get-cluster}}, AlarmActionsEnabled
    $hostsalarmsactions = @()
    $hostsalarmsactions += $actions
    }

    If (($hostsalarmsactions | Measure-Object).count -gt 0) {
    $MyReport += Get-CustomHeader “1” “Host(s) with Alarm Actions Disabled”
    $MyReport += Get-HTMLTable $hostsalarmsactions
    $MyReport += Get-CustomHeaderClose
    }
    }

  10. Chris

    I just noticed something with the “Host Alarms” Section. I don’t get any results when digging into the variable $hoststriggeredalarms. For instance $hosttriggeredalarms[0].alarm.value is blank. Running $hosttriggeredalarms returns all results. This makes this portion blank: $Details.Alarm = ($valarms | where {$_.value -eq ($hostsTriggeredAlarm.alarm.value)}).name … Maybe it’s my environment, but I’m stumped as to why. I’m running vCenter 4, ESX 3.5 hosts, PowerCLI 4U1, and Powershell 2.0.

  11. Hase3d

    Once again, many thanks for this great script.. I have edited the line for — No VM Tools —- to get the script to list if a VM has wrong version of tools installed -eq ToolsOld. Before the line looked like

    $NoTools = @($FullVM | Where {$_.Runtime.Powerstate -eq “poweredOn” -And ($_.Guest.toolsStatus -eq “toolsNotInstalled” -Or $_.Guest.ToolsStatus -eq “toolsNotRunning”)} | Select Name, @{N=”Status”;E={$_.Guest.ToolsStatus}})

    and after the change

    $NoTools = $FullVM | Where {$_.Runtime.PowerState -eq “poweredOn” -And ($_.Guest.toolsStatus -eq “toolsNotInstalled” -Or $_.Guest.ToolsStatus -eq “toolsNotRunning” -Or $_.Guest.ToolsStatus -eq “toolsOld”)} | Select Name, @{N=”Status”;E={$_.Guest.ToolsStatus}}

    This will add the toolsOLD Status in the report.

    and also I´ve changed the e-mail sending function to use the send-mailmessage cmdlet instead of .NET framework class, this is because I hade some trouble getting the script to send an e-mail to multiple reciepients.

    I just deleted these lines

    function Send-SMTPmail($to, $from, $subject, $smtpserver, $body) {
    $mailer = new-object Net.Mail.SMTPclient($smtpserver)
    $msg = new-object Net.Mail.MailMessage($from,$to,$subject,$body)
    $msg.IsBodyHTML = $true
    $mailer.send($msg)
    }

    And changed the value Send-SMTPmail to Send-Mailmessage on row 498 and 1000 and also added

    Send-MailMessage -To $EmailTo -From $EmailFrom -Subject “$VISRV Daily Report” -SmtpServer $SMTPSRV -BodyAsHtml $MyReport

    instead of

    Send-MailMessage $EmailTo $EmailFrom “$VISRV Daily Report” $SMTPSRV $MyReport

    Looking forward to more great functions in this script.

  12. Ed

    This is a great script. Makes keeping an eye on my VM environment much easier.

    I do have one problem I keep getting. I get the following error when I try to run the script. I got the same thing with version 2. Any thoughts on why?

    12:43 ..Checking Snapshots
    Exception calling “ReadNextTasks” with “1” argument(s): “A general system error occurred: Object not found”
    At :line:436 char:45
    + $collection = $collectionImpl.ReadNextTasks <<<< ($tasknumber)

  13. Caipirinha

    Hi Alan,
    first of all I would like to say that you do a good job and your scripts help us to do our work better!

    I find your new feature “Dead Lun Path” grate, but maybe there is a Bug.
    The script told me that we have a problem with some vmhbas.

    esx2f1.douglas-informatik.de vmhba1:0:1 Dead
    esx2f1.douglas-informatik.de vmhba1:1:1 Dead
    esx2f1.douglas-informatik.de vmhba1:2:1 Dead

    That was right and we fixed the physical problem so far, but your script told us still the same problem. I can’t find any dead path at the service console.
    Do you have any idea?

    Best Marcel

  14. Steve

    Hi,

    I am new to vmware scripting, could you please help to point me to some instruction on how to run this daily report.

    you have done a great job in producing this daily report script.

    hope to hear from you soon

    Best Regards,

    Steve

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.