# Load Windows PowerShell cmdlets for managing vSphere
Add-PsSnapin VMware.VimAutomation.Core -ea "SilentlyContinue"
#provide option for optional path (TODO)
$pathToOVF = "C:\ovf\vCCNode-2.7.1.0-2651441_OVF10.ovf"
$vc = "vCenter address"
echo "Connecting to $vc"
$adUserAccount = "$([Environment]::UserDomainName)\$([Environment]::UserName)"
# get the AD username running this script
$creds = Get-Credential -UserName $adUserAccount -Message "Please enter your AD Password"
$username = $creds.username
$password = $creds.GetNetworkCredential().password
# Get current domain using logged-on user's credentials
$CurrentDomain = "LDAP://"+([ADSI]"").distinguishedName
$domain = New-Object DirectoryServices.DirectoryEntry($CurrentDomain,$username,$password)
if ($domain.name -eq $null)
{
write-host "Authentication failed - please verify your username and password."
exit #terminate the script.
}
else
{
write-host -foregroundcolor Green "Successfully authenticated with LDAP" #>
$vi = "vi://$username:$password@$vc"
#Connect to vCenter
write-host -foregroundcolor Green "Connecting to vCenter"
Connect-VIServer -Server $vc -User $username -Password $password
#Get Datastores
write-host ""
write-host "##############################################################################"
write-host ""
write-host -foregroundcolor Green "Retrieving Datastores"
#get-datastore | Select Name, @{N="FreeSpaceGB";E={[System.Math]::Round($_.FreeSpaceMB / 1024, 2)}} , @{N="CapacityGB";E={$_.CapacityMB / 1024}}, @{N="UsedGB";E={[System.Math]::Round(($_.CapacityMB - $_.FreeSpaceMB) / 1024, 2)}}
#Prompt datastore selection
$datastores = get-datastore | select Name,FreeSpaceMB
#Sets some static info
$LargestFreeSpace = "0"
$LargestDatastore = $null
#Performs the calculation of which datastore has most free space
foreach ($datastore in $datastores) {
if ($Datastore.FreeSpaceMB -gt $LargestFreeSpace) {
$LargestFreeSpace = $Datastore.FreeSpaceMB
$LargestDatastore = $Datastore.name
}
}
#Writes out the result to the PowerShell Console
write-host "$LargestDatastore has been selected as the largest datastore with $LargestFreeSpace MB Free Space"
write-host ""
write-host "##############################################################################"
write-host ""
$env = "enter port group name could be partial dmz* etc"
#Lookup port group
write-host -foregroundcolor Green "Retrieving Port Groups"
$pg = get-VirtualPortgroup -Name $env | select Name
$pgt = $pg.Name.SubString(0)
echo "Port group selected is $pgt"
write-host ""
write-host "##############################################################################"
write-host ""
# Calculate or assign IP's to variables
echo "GW will be set to XXX"
echo "DNS will be set to XXX"
echo "Network IP will be set to XXX"
echo "Subnet Mask will be set to XXX"
write-host ""
write-host "##############################################################################"
write-host ""
$name="xxx"
& 'C:\Program Files\VMware\VMware OVF Tool\ovftool.exe' --allowExtraConfig --acceptAllEulas --powerOn --name=$name --diskMode=thick --datastore="$LargestDatastore" --network="$pgt" --prop:vami.DNS.VMware_vCloud_Connector_Server="XXX" --prop:vami.netmask0.VMware_vCloud_Connector_Server="255.255.255.192" --prop:vami.ip0.VMware_vCloud_Connector_Server="XXX" --prop:vami.gateway.VMware_vCloud_Connector_Server="XXX" "$pathToOVF" " $vi"