Skip to content

Instantly share code, notes, and snippets.

@ewypych
Created February 18, 2017 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ewypych/fb08e4a8b52d6c60af0832801c89180b to your computer and use it in GitHub Desktop.
Save ewypych/fb08e4a8b52d6c60af0832801c89180b to your computer and use it in GitHub Desktop.
PowerCLI script for Windows VMs searching - VMware vCloud Director
##################################################################
#
# Script gets any Windows machine from the vCloud Director host
# with its status, GuestOS, CPU count and Memory
#
# Created by: Emil Wypych
# Created on: 16.02.2017
#
##################################################################
# Read your vCloud Host
$vcloud = Read-Host "Give the name of the vCloud Director: "
# Enter the CSV file to be created
$csvfile = "VM_Windows.csv"
Connect-CIServer $vcloud
# Create the CSV title header
Add-Content $csvfile "VM,HostName,Status,GuestOSFullName,Cpu,Memory,Env,ProviderVdc"
# Uncomment what you want
# Get all Windows machines from the whole vCloud Director
#$vms = Get-CIVM | Where-Object {$_.GuestOSFULLName -Match "Windows"}
# Get all Windows excluding VMs from ProviderVdc matches "TEST"
#$vms = Get-ProviderVdc | Where-Object {$_.Name -notmatch "TEST"} | Get-OrgVdc | Get-CIVM | Where-Object {$_.GuestOSFULLName -Match "Windows"}
# Get all Windows VMs only from ProviderVdc matches "TEST"
#$vms = Get-ProviderVdc | Where-Object {$_.Name -match "TEST"} | Get-OrgVdc | Get-CIVM | Where-Object {$_.GuestOSFULLName -Match "Windows"}
# Create list of VMs
foreach ($VM in $vms) {
$name = $VM.Name
$guestName = $VM.ExtensionData.Section.ComputerName
$status = $VM.Status
$guestos = $VM.GuestOSFullName
$CPU = $VM.CpuCount
$RAM = $VM.MemoryGB
$env = $VM.OrgVdc
$providervdc = $VM.OrgVdc.ExtensionData.ProviderVdcReference.Name
# Create row contains VM name, hostname of VM, power status, full name of the guest OS, CPU count, RAM in GB, Org vDC, Provider Vdc
$write = "$name, $guestName, $status, $guestos, $CPU, $RAM, $env, $providervdc"
Add-Content $csvfile $write
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment