Windows Powershell Script to export vmware vcenter machines’ data in a CSV file

=====================START =====================

Connect-VIServer -Server “vcenter-fqdn” -User “domain\vmwareuser” -Password “xxxxx”

Get-VM | `
ForEach-Object {
$VM = $_
$VMview = $VM | Get-View
$VMResourceConfiguration = $VM | Get-VMResourceConfiguration
$VMHardDisks = $VM | Get-HardDisk
$HardDisksSizesGB = @()
$Temp = $VMHardDisks | ForEach-Object { $HardDisksSizesGB += [Math]::Round($_.CapacityKB/1MB) }
$VmdkSizeGB = “”
$Temp = $HardDisksSizesGB | ForEach-Object { $VmdkSizeGB += “$_+” }
$VmdkSizeGB = $VmdkSizeGB.TrimEnd(“+”)
$TotalHardDisksSizeGB = 0
$Temp = $HardDisksSizesGB | ForEach-Object { $TotalHardDisksSizeGB += $_ }
$Snapshots = $VM | Get-Snapshot
$Report = “” | Select-Object VMname,Status,Hostname,IPaddresses,GuestOS,Description,ESXname,MemoryGB,vCPUcount,vNICcount,VmdkSizeGB,TotalVmdkSizeGB
$Report.VMName = $VM.name
$Report.Status = $VM.Guest.State
$Report.Hostname = $VM.guest.hostname
$Report.IPaddresses = [String]$VM.Guest.IPAddress
$Report.GuestOS = $VM.Guest.OSFullName
$Report.Description = $VM.Notes
$Report.ESXname = $VM.VMHost
#$Report.ClusterName = ($VM | Get-Cluster).Name
$Report.MemoryGB = $VM.MemoryMB/1024
$Report.vCPUcount = $VM.NumCpu
$Report.vNICcount = $VM.Guest.Nics.Count
$Report.VmdkSizeGB = $VmdkSizeGB
$Report.TotalVmdkSizeGB = $TotalHardDisksSizeGB
#$Report.DatastoreName = $VMview.Config.DatastoreUrl
#$Report.ToolsVersion = $VMview.Config.Tools.ToolsVersion
#$Report.ToolsUpdate = $VMview.Guest.ToolsStatus
#$Report.NumCpuShares = $VMResourceConfiguration.NumCPUShares
#$Report.CpuLimitMHZ = $VMResourceConfiguration.CpuLimitMhz
#$Report.CpuReservationMHZ = $VMResourceConfiguration.CpuReservationMhz
#$Report.NumMemShares = $VMResourceConfiguration.NumMemShares
#$Report.ReservationsMB = $VMResourceConfiguration.MemReservationMB
#$Report.LimitMB = $VMResourceConfiguration.MemLimitMB
#$Report.SnapshotCount = (@($VM | Get-Snapshot)).Count
Write-Output $Report
} | sort $VM.name | Export-Csv “C:\export.csv” -NoTypeInformation

=====================END =====================

Advertisements

Free PowerShell Script Browser and Script Analyzer

Post source: vladan

There is a free utility from Microsoft which allows to browse published PowerShell script on Technet script center repository. A repository where there is over 9000 script samples. The utility lets you search within the environment The searches can be done through a window where you can also sort the scripts by date, popularity, author or number of downloads.

If you’re looking for a script which has already been built, then this tool is for you. Why create something that has already been created? I find this quite valuable.

Powershell Script Browser and Script Analyser has two tools:

  • Script browser – the search window
  • PowerShell ISE – which is the Integrated PowerShell Environment (ISE)

On the image below you can see the search window.

script browser Free PowerShell Script Browser and Script Analyzer

The ISE environment looks like this.

ise env Free PowerShell Script Browser and Script Analyzer

Quote from Technet:

Windows PowerShell ISE is a host application that enables you to write, run, and test scripts and modules in a graphical and intuitive environment. Key features in Windows PowerShell ISE include syntax-coloring, tab completion, Intellisense, visual debugging, Unicode compliance, and context-sensitive Help. It provides a rich scripting experience.

Practical applications:

  • To help you manage and automate your environment, Windows PowerShell ISE includes the following features:
  • The ability to run interactive commands in a console pane, just as you would in the Windows PowerShell console. Simply type a command, and then press ENTER.
  • The ability to create, edit, debug, and run functions, workflows, scripts, and modules in a script pane.
  • Multiple Windows PowerShell tabs, each with a console and script pane, to enable you to simultaneously work on several independent tasks.
  • The ability to edit text in complex scripts and right-to-left languages.

The utility is in its version 1.3 right now and can be downloaded from this page.

VMware Tools one-liners using PowerCli

VMware Tools one-liners using PowerCli

Post source Pario

This short post is about VMware Tools on VM guests running in a vSphere 5.x cluster/hosts.

“Connect by using integrated authentication. In this case, the credentials you are logged on to your machine must be the same as those for the server”

Connect-VIServer Server

This PowerCli one-liner creates a list of VM guests where the VMware Tools CDROM/ISO is mounted:

(Get-VM | Get-View | Where {$_.Runtime.ToolsInstallerMounted}) | % {$_.Name}

Unmount the VMware Tools installer CDROM on all VM guests. This is useful to run before you try to put at ESXi host in maintenance mode because VM guests thatare installing VMware Tools will not migrate because the VMware Tools is not on a shared storage. You will get the error message “The virtual machine is installing VMware Tools and cannot initiate a migration operation”.

(Get-VM | Get-View | Where {$_.Runtime.ToolsInstallerMounted}) | % {Dismount-Tools }

This last one finds all VM guests running Windows as guest OS and upgrades VMware Tools without a reboot at the end

Get-VM | Where {$_.PowerState -eq “PoweredOn” -and $_.Guest.OSFullName -match “Win*”} | % {Update-Tools -VM $_ -NoReboot}

VM Tools and Virtual Hardware Versions

Get-VM | Select Name, Version

But the returned object doesn’t have a root property for ToolsVersion or ToolsVersionStatus, for this we need to delve into the ExtensionData property and have a look around, once we have found the information it is fairly easy to add these to our object using the New-VIProperty cmdlet as below:

New-VIProperty -Name ToolsVersion -ObjectType VirtualMachine `
-ValueFromExtensionProperty ‘Config.tools.ToolsVersion’ `
-Force

New-VIProperty -Name ToolsVersionStatus -ObjectType VirtualMachine `
-ValueFromExtensionProperty ‘Guest.ToolsVersionStatus’ `
-Force

Now we have added these as a new property to our object (actually they are PowerShell Code Properties), we can use our old friend Get-VM to retrieve the information easily:

Get-VM | Select Name, Version, ToolsVersion, ToolsVersionStatus

Of course we can choose which list of VMs to get this information for:

For a Datacenter: Get-Datacenter London | Get-VM | Select Name, Version, ToolsVersion, ToolsVersionStatus

For a cluster: Get-Cluster Production | Get-VM | Select Name, Version, ToolsVersion, ToolsVersionStatus

For a host: Get-VMHost Host1.mydomain.local | Get-VM | Select Name, Version, ToolsVersion, ToolsVersionStatus

And we can also easily export this information into a csv file:

Get-VM | Select Name, Version, ToolsVersion, ToolsVersionStatus | Export-Csv -NoTypeInformation -UseCulture -Path C:\Temp\VMHWandToolsInfo.csv

Update sequence for vSphere 5.5 and its compatible VMware products

http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2057795

 

Update sequence for vSphere 5.5 and its compatible VMware products (2057795)

Purpose

VMware has made available certain releases to address critical issues for several products including:

  • vCloud Director (VCD)
  • vCloud Networking and Security (VCNS) (formerly vShield Manager)
  • Horizon View
  • vCenter Server
  • vSphere Replication (VR)
  • vCenter Site Recovery Manager (SRM)
  • vCenter Operations Manager (vCOPS)
  • vSphere Data Protection (VDP)
  • vSphere Storage Appliance (VSA)
  • ESXi
  • vShield Edge
  • vShield App
  • vShield Endpoint

This article only encompasses environments running vSphere 5.5 and VMware products compatible with vSphere 5.5.

In an environment with vSphere 5.5 and its compatible VMware products, follow the update sequence described in the Supported Update Sequence table.

Note: This article refers only to the latest versions of VMware products that are supported by vSphere 5.5 and its update sequence. For a complete list of VMware products compatible with vSphere 5.5, see VMware Product Interoperability Matrixes.

Resolution

This table describes the sequence in which the vSphere 5.5 and its compatible VMware products must be updated:

Supported Update Sequence

  VCD VCNS View Composer View Connection Server VSA Manager vCenter Server VR / SRM vCOPS VDP ESXi VMware Tools vShield Edge vShield App vShield Endpoint View Agent / Client
Update Sequence Number 1                            
  2                          
    3                        
      4 4**                    
          5*                  
            6 6 6            
                  7*          
                    8        
                      9 9 9 9

* If you are using a Cisco Nexus 1000V, see vSphere 5.5 and its compatible third-party products in the Additional Information section of this article before upgrading vCenter Server (sequence step 5) or the ESXi hosts (sequence step 7).

Note: If you need to update multiple products in your environment, start with updating the product with the lowest sequence number. After you update the product, update the product with the next sequence number. If a product is not present in your environment, update the subsequent product. If you need to update two products with the same sequence number, the order of update does not matter.

Before you update vCenter Server, disable vCenter Server from vCloud Director. Also ensure that you stop or disable other VMware services so that they do not communicate with vCenter Server during the update process. For more information, see the product documentation.

Sample VMware product upgrade scenarios

Example 1

If you have the vCloud Director solution stack installed in your environment, the supported patch update sequence is:

  1. Update vCloud Director (sequence step 1)
  2. Update vCloud Networking and Security (vShield Manager) (sequence step 2)
  3. Update vCenter Server (sequence step 5)
  4. Update ESXi (sequence step 7)
  5. Update vShield Edge (sequence step 9)

Example 2

If you have SRM solution installed in your environment, the supported patch update sequence is:

  1. Update vCenter Server (sequence step 5)
  2. Update vSphere Replication (sequence step 6)
  3. Update ESXi (sequence step 7)

Example 3

If you have the vSphere Data Protection solution installed in your environment, the supported patch update sequence is:

  1. Update vCenter Server (sequence step 5)
  2. Update vSphere Data Protection (sequence step 6)
  3. Update ESXi (sequence step 7)

Example 4

If you have the vSphere Storage Appliance solution installed in your environment, the supported patch update sequence is:

  1. Update vSphere Storage Appliance Manager (sequence step 4)
    1. For a 2 node VSA cluster, see Upgrade a Two-Node VSA Environment in the vSphere Storage Appliance Installation and Administration guide
    2. For a 3 node VSA cluster, see Upgrade a Three-Node VSA Environment in the vSphere Storage Appliance Installation and Administration guide
  2. Update vCenter Server (sequence step 5)
  3. Update vSphere Storage Appliance Cluster (sequence step 6)

Example 5

If you have a Cisco Nexus 1000V virtual distributed switch solution installed in your environment, the supported patch update sequence is:

  1. Verify with Cisco the compatibility for the Nexus upgrade procedure. This will dictate the order for upgrading the vCenter Server and the ESXi hosts.
  2. Update vCenter Server (sequence step 5)
  3. Update ESXi (sequence step 7)

Note: If you are using the vSphere Client in your environment, VMware recommends that you upgrade the vSphere Client to version 5.5.

vSphere 5.5 and its compatible VMware products

This table provides information about the current version of released VMware products and the recommended action required to patch to the next level. The table also provides reference links to release notes and update procedure documents.

vSphere 5.5 and its compatible VMware products

Product Version Recommended Action Important Links
vCloud Director (VCD) 5.5.0 Update to 5.5.0 Release Notes
Update Procedure
vCloud Networking and Security (VCNS) 5.5.0 Update to 5.5.0 Release Notes
Update Procedure
Horizon View (View) 5.2.0 Update to 5.2.0 Release Notes
Update Procedure
vCenter Server 5.5.0 Update to 5.5.0 Release Notes
Update Procedure
vSphere Replication (VR) / vCenter Site Recovery Manager (SRM) 5.5.0 Update to 5.5.0 VR Release Notes
SRM Release Notes
Upgrading VR
Upgrading VR without internet access
Upgrading SRM
vCenter Operations Manager (vCOPS) 5.7.2 Update to 5.7.2 Release Notes
Update Procedure
vSphere Data Protection (VDP) 5.5.1 Update to 5.5.1 Release Notes
Update Procedure
vSphere Storage Appliance (VSA) 5.5 Update to 5.5 Release Notes
Update Procedure
ESXi 5.5.0 Update to 5.5.0 Release Notes
Update Procedure
vShield Edge 5.5.0 Update to 5.5.0 Release Notes
Update Procedure
vShield App 5.5.0 Update to 5.5.0 Release Notes
Update Procedure
vShield Endpoint 5.5.0 Update to 5.5.0 Release Notes
Update Procedure