Created
February 18, 2017 14:24
-
-
Save ewypych/fb08e4a8b52d6c60af0832801c89180b to your computer and use it in GitHub Desktop.
PowerCLI script for Windows VMs searching - VMware vCloud Director
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################## | |
# | |
# 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