Powershell script to ping servers

I created the following script to check some VM’s at home. This script pings all the servers from the CSV file. If a ping has failed, the script will send an e-mail with the servername and ip-address.

If you want to use this script, you have to change/create the following items:

  • Create a CSV file with your servers and ip-addresses
  • Enter your SMTP Server and e-mail address in the powershell script
  • Schedule the powershell script


The CSV file will contain the following information:



The Powershell script:

$servers = "D:\scripts\ps\servers.csv"
$csv = Import-CSV $servers 
$smtpServer = ""

foreach($item in $csv){
    $server = $item.ServerName
    $ip = $item.IpAddress

    $ping = new-object System.Net.NetworkInformation.Ping
    $rslt = $ping.send($ip)
        if ($rslt.status.tostring() –eq "Success") {
            write-host ping worked on $server with $ip -ForegroundColor Green}
        else {
            write-host ping failed on $server with $ip -ForegroundColor Red
            # Send E-Mail
            $msg = new-object Net.Mail.MailMessage
            $smtp = new-object Net.Mail.SmtpClient($smtpServer)
            $msg.From = "@"
            $msg.Subject = "Warning: ping failed on $server"
            $msg.Body = "The server $server with ip adres $ip does not reply!"
$ping = $null

The source of the ping script: http://theessentialexchange.com/blogs/michael/archive/2007/11/13/checking-server-availability-in-powershell.aspx

Script: RemoveHBA.sh is ESX3.5 u4 ready


Bouke released a new version of his RemoveHBA.sh script. The new version is also compatible with ESX 3.5 update 4:

This new removehba script removes the HBA drivers from the ESX 3.x ISO. Added support for 3.5 U1, U2, U3 & U4. VMware changed some files where the drivers were in and the script is taking care of that now also.

Download the script here: http://www.jume.nl

Powershell: Check if KB patch is installed

Ik wilde weten of een bepaald KB nummer was geïnstalleerd op mijn VM’s. Dit wilde ik natuurlijk niet met het handje nakijken en heb hiervoor een script bij elkaar geraapt.

Het onderstaande script kun je gebruiken in een VMware VI omgeving.

#Add-PSSnapIn VMware.VimAutomation.Core

# Connect to vCenter
$VC = Connect-VIServer (Read-Host "Enter vCenter server")

# Enter the KB#
$HotFixID = (Read-Host "Enter KB#")

# Get all VM’s with powerstate = PoweredOn
$VMS = Get-VM | Where {$_.PowerState -eq "PoweredOn"} | Sort Name

ForEach ($VM in $VMS)

# Process only Windows Server VM’s
if ($VM.Guest.OSFullName -match "Microsoft Windows Server*")
# Get all the info using WMI
  $results = get-wmiobject -class "Win32_QuickFixEngineering" -namespace "root\CIMV2" -ComputerName $VM 
    # Loop through $results and look for a match then output to screen
    foreach ($objItem in $results)
                # Do the match
                if ($objItem.HotFixID -match $HotFixID)
                    write-host $objItem.CSName
                    write-host "Hotfix "$HotFixID" installed"
# Disconnect from vCenter
Disconnect-VIServer -Confirm:$False


Zodra je het script start, word er gevraagd naar de vCenter server en het KB nummer wat je wilt nakijken.


De volgende output wordt gegenereerd:



Je kunt het onderstaande script gebruiken in een omgeving zonder VI3:

# Get content
$computers = get-content c:\computers.txt

# Get all the info using WMI
$results = get-wmiobject -class “Win32_QuickFixEngineering” -namespace “root\CIMV2″ -computername $computers

# Loop through $results and look for a match then output to screen
foreach ($objItem in $results)
    if ($objItem.HotFixID -match “KB932168″)
        write-host $objItem.CSName
        write-host “Hotfix KB932168 installed”


Source: http://techittome.wordpress.com/2007/04/12/windows-powershell-script-to-check-for-specific-hotfix/

Script: VI Toolkit Healthcheck

Ivo Beerens just released his second version of his Healthcheck powershell script.

Version 2.0 of the Healthcheck script is released. The script reports the following:

– VMware ESX server Hardware and version         
– VMware vCenter version    
– Cluster information
– VMware statistics
– Active Snapshots    
– CDROMs connected to VMs   
– Floppy drives connected to VMs  
– Datastores Information such as free space
– RDM information 
– VM information such as VMware tools version,  processor and memory limits     
– VM’s and there datastore
– VMware timesync enabled  
– Percentage disk space used inside the VM
– VC error logs last 5 days

It is possible to schedule this script and output the content to HTML and e-mail it. 


You can download the script over here: http://www.ivobeerens.nl/?p=256

Script: Defrag all Local VMDK’s.


De volgende function zoekt eerst alle *.VMX bestanden op en vervangt daarna de extentie *.VMX naar *.VMDK. Deze *.VMDK bestanden worden in de $List geplaatst. Daarna worden alle VMDK’s gedefragmenteerd via de vmware-vdiskmanager.exe.

function Defrag-allVMDKs{
$vdiskmanager = “C:\Program Files\VMware\VMware Workstation\vmware-vdiskmanager.exe”
$parameter = “-d”
$List = get-childitem $path -recurse | where {$_.extension -eq “.vmx”} |
foreach-object -process { $_.FullName } | ForEach-Object {$_ -replace “.vmx”, “.vmdk”}
ForEach($vmdk in $List)
echo $vmdk
& $vdiskmanager $parameter $vmdk

Via het volgende commando kun de bovenstaande function gebruiken.

Defrag-allVMDKs <drive>\<path>

Als je dit in de Shell uitvoerd ziet het er als volgt uit:


How To: Schedule a Powershell script with Scheduled Task


In deze post lees je hoe je een Powershell script kunt schedulen via Windows Scheduled Tasks.

Start de Scheduled Task Wizard.


Klik op Browse… en voeg het onderstaande commando in:



Nadat de wizard klaar is, vink je Open advanced properties for this task when I click Finish aan. Daarna voeg je het volgende toe aan het Run veld: -command D:\Scripts\backupwsvm.ps1


Vervolgens druk je op OK om de task op te slaan.

Mocht je een Powershell script scheduled die gebruik maakt van de VI Toolkit. Dan moet je de onderstaande code toevoegen aan je script.

Add-PSSnapin -Name “VMware.VimAutomation.Core”


Citrix: CPSUpdate script

Thomas Koetzing van http://www.thomaskoetzing.de heeft zijn CPSUpdate script voorzien van een update.

I have now extended the update script to automatically download ALL currently available Hotfixes/Rollups for the xenApp (Presentation Server) I have set. This is done with the Windows version of the unix command "wget". Wget also supports proxy settings and can be set in the script as well.

Right now xenApp 5.x is not supported because the is no fix available and I have to check what Citrix is doing there…This is the 1.8 release with the download option, so let me know of any bug etc.
Please leave your comment at the bottom of the article how to patch Presentation Server.

Download het script hier: CPSUpdate-v1.8.zip