So it seems I'm never done with this script. I want there to be default answers in some areas, and if a user passes something that's invalid it asks again until they pass a proper bit of info.
$type = Read-Host "Enter Host or Cluster"
if ($type -eq "Cluster")
{
Get-Cluster | Select Name | sort Name | Format-List #Gets a list of clusters in the vCenter#
$Cluster = Read-Host "Enter Cluster Name"
$myCluster = Get-Cluster -Name "$Cluster"
Get-VMHost -Location "$myCluster" -state "Connected" | sort Name | Select Name,ConnectionState,PowerState | Format-Table #Lists the host from the cluster specified earlier#
}
else
{
Get-VMHost | where {$_.state -eq "Connected"} | sort Name | Select Name,ConnectionState,PowerState | Format-Table
}
$vmHost = Read-Host "Enter host name"
Get-Datastore -VMHost $vmHost | where {$_.type -eq "NFS"} | Select @{N="Cluster";E={$cluster.Name}},Name,CapacityGB,FreespaceGB,@{N='UsedSpace';E={$_.FreeSpaceGB/$_.CapacityGB*100}} | Out-Default #Lists datastores and capacity#
$datastore = Read-Host "Enter Datastore Name"
$myDatastore = Get-DataStore -Name "$datastore"
$ovfhost = Read-Host "Enter path to OVA/OVF"
$vmName = Read-Host "Enter a name for the VM"
$diskStorage = Read-Host "Enter Thin, Thick or EagerZeroedThick for disk format"
Import-vApp -Source "$ovfhost" -VMHost $vmHost -Location $myCluster -Name "$vmName" -DiskStorageFormat $diskStorage -Datastore $myDatastore #Imports the OVA/OVF into vCenter#
Sleep 10
$VMmove = Read-Host "Enter folder to move VM to"
Move-VM -VM $vmName -Destination $VMmove #Moves VM to the appropriate folder#
Get-Cluster -Name "$Cluster" | Get-VMHost -Name "$vmHost" | Foreach-Object {$strClusterName = $_.Parent.Name; Get-VirtualPortGroup $_ | Select-Object @{N="Cluster";E={$strClusterName}},Name,VLanId} #Gets available VLANs from the host#
$VLAN = Read-Host "Please enter the VLAN name to use"
$NIC = Get-NetworkAdapter -VM $vmName
So for the first part for $type it defaults to Host which I'm fine with. After that I get a list of only hosts that are in the Connected state. I'd like it if someone could just only type a name from the list provided, and if they don't provide one it prompts again. Same thing would be fore the rest really, for the datastore, disk storage, folder path (hoping they put in a valid path) and VLAN type. I'm new to all of this and have been googling around, just haven't found what I need yet.