Change all ESX root passwords

Another great script from Arnim van Lieshout.

With this script you can change all ESX root passwords at once:

#
# This script changes the root password on all ESX hosts in the esxservers.txt textfile
# 

# Add VI-toolkit #
Add-PSsnapin VMware.VimAutomation.Core
Initialize-VIToolkitEnvironment.ps1# Get old root credential
$oldrootPassword = Read-Host “Enter old root password” -AsSecureString
$oldrootCredential = new-object -typename System.Management.Automation.PSCredential -argumentlist “root”,$oldrootPassword

# Get new root credential
$newrootPassword = Read-Host “Enter new root password” -AsSecureString
$newrootCredential = new-object -typename System.Management.Automation.PSCredential -argumentlist “root”,$newrootPassword
$newrootPassword2 = Read-Host “Retype new root password” -AsSecureString
$newrootCredential2 = new-object -typename System.Management.Automation.PSCredential -argumentlist “root”,$newrootPassword2

# Compare passwords
If ($newrootCredential.GetNetworkCredential().Password -ceq $newrootCredential2.GetNetworkCredential().Password) {

 # Create new root account object
 $rootaccount = New-Object VMware.Vim.HostPosixAccountSpec
 $rootaccount.id = “root”
 $rootaccount.password = $newrootCredential.GetNetworkCredential().Password
 $rootaccount.shellAccess = “/bin/bash”

 # Get list of Host servers from textfile to change root password on
 Get-Content esxservers.txt | %{
  Connect-VIServer $_ -User root -Password $oldrootCredential.GetNetworkCredential().Password -ErrorAction SilentlyContinue -ErrorVariable ConnectError | Out-Null
  If ($ConnectError -ne $Null) {
   Write-Host “ERROR: Failed to connect to ESX server:” $_
  }
  Else {
   $si = Get-View ServiceInstance
   $acctMgr = Get-View -Id $si.content.accountManager
   $acctMgr.UpdateUser($rootaccount)
   Write-Host “Root password successfully changed on” $_
      Disconnect-VIServer -Confirm:$False | Out-Null
  }
 }
}
Else {
Write-Host “ERROR: New root passwords do not match. Exiting…”
}

Example esxservers.txt:

esx001.yourdomain.local
esx002.yourdomain.local
esx003.yourdomain.local
esx004.yourdomain.local

Download: [wpdm_file id=9]

List all vm’s and total assigned diskspace

Looking for new scripts i’ve stumbled opon the following script to list all vm’s to an excel sheet and display the total assigned diskspace:

# Define Variables 
$outputFile = 'C:\VMDiskCapacity.csv' 
$VCServer = "vcenter.mydomain.com" 
$username = "vcenter_admin" 
$pass = "password" 

################## 
# Add VI-toolkit # 
################## 
Add-PSsnapin VMware.VimAutomation.Core 
Initialize-VIToolkitEnvironment.ps1 

# Connect server 
$VC = Connect-VIServer -Server "$VCServer" -User "$username" -Password "$pass" 

$myCol = @()    # Prepare output collection 
$VMs = Get-VM | sort Name    # Get all VMs (sorted) 
$counter = 0    # Initialize counter for progress bar 
ForEach ($VM in $VMs)    # Loop through VMs 
   { 
   $counter++    # Increase counter for progress bar 
   Write-Progress -Activity "Gathering disk information" -Status "Processing VM $VM" -PercentComplete (100*($counter/$VMs.count))    # Display progress bar 
    
   $myObj = "" | 
   select VM, TotalDiskSizeGB # Create output object 
   $myObj.VM = $VM.Name    # Virtual Machine Name 
    
   $TotalDiskSizeKB = 0 
   ForEach ($DISK in $VM.HardDisks)    # Loop through VM's harddisks 
      { 
      $TotalDiskSizeKB += $DISK.CapacityKB    
      } 
    
   $myObj.TotalDiskSizeGB = [math]::Round(($TotalDiskSizeKB * 1KB / 1GB),0) #Disk Size in GB 
   $myCol += $myObj    # Add output to collection 
   } 
$myCol | Export-Csv $outputFile -NoTypeInformation  # Export output to csv 

Running PowerShel Scripts to generate ESX Reports

In my previous post i have written about a script that gave an output of the datastore usage of your esx hosts. For this you need to run a powershell script against your virtual center server.

Before you can run this script you have a few requirement, this requirements are:

After installing the Microsoft PowerShell and VI Toolkit for Windows you have to place your scripts in the script directory (c:\program files\vmware\infrastructure\vitoolkitforwindows\scripts)

Check your rights, it should be unrestricted: “powershell get-executionpolicy”.
If your result is: “Restricted”, type in the following command: “powershell set-executionpolicy unrestricted”

Now you can run your scripts by starting the “VMware VI Toolkit (for windows)”, this option can be found under start > programs > vmware > vmware vi toolkit

VMware ESX Datastore Reports – PowerShell

Using Microsft PowerShell and the VI Toolkit for Windos you can do some nice stuff. When looking for a way to make reports for a customer of my i’ve stumbled upon a few scripts.

All you have to do is to install Microsoft Powershell, VI toolkit for windows and have Office on your machine. When running the powershell script [wpdm_file id=”4″] i get the following output:

Datastore Chart

Contents of datastore.ps1:

if ((Test-Path  REGISTRY::HKEY_CLASSES_ROOT\OWC11.ChartSpace.11) -eq $False)
{
       Write-Host "This script requires Office Web Components to run correctly, please install these from the following website: http://www.microsoft.com/downloads/details.aspx?FamilyId=7287252C-402E-4F72-97A5-E0FD290D4B76&displaylang=en"
       exit
}
connect-VIServer yourserver

$Caption = "Datastore Usage %"

$categories = @()
$values = @()
$chart = new-object -com OWC11.ChartSpace.11
$chart.Clear()
$c = $chart.charts.Add(0)
$c.Type = 4
$c.HasTitle = "True"
$series = ([array] $chart.charts)[0].SeriesCollection.Add(0)

Get-datastore |Sort-Object FreeSpaceMB -Descending | foreach-object {

        $capacitymb = $_.CapacityMB
        $FreeSpaceMB = $_.FreeSpaceMB
        $UsedSpace = $capacitymb - $freespacemb

        $perc = $UsedSpace / $capacitymb * 100

        $categories += $_.Name
        $values += $perc * 1
}

$series.Caption = $Caption
$series.SetData(1, -1, $categories)
$series.SetData(2, -1, $values)
$filename = (resolve-path .).Path + "\Chart.jpg"
$chart.ExportPicture($filename, "jpg", 800, 500)
invoke-item $filename

Command from here

Run the register file and when you do a right click on a folder you get the extra option “command prompt”. When you select the option a dos box will open on that location.

Download [wpdm_file id=”2″] or save the following lines in a file (whith extension “reg”) and run it on you machine:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\Command Prompt\Command]
@="Cmd.exe /k pushd %L"

Check multiple Dell Asset Tags for warranty

march 6, 2012: Dell recently changed the warranty site so this script will not work anymore. Please see https://sourceforge.net/projects/dellwt/ for a program which searches the information for you.

———————————————————————————

Use the attached script to check multiple Dell Asset tags for warranty (place all asset tags in a file called: “DellServiceTags.txt”):

download: [wpdm_fileid=”5″]

When run it uses the service tags from the text file to create a csv file (results.csv). Below is an example off the results.csv file in excel.