#Read the VCenter FQDN from a config file: Echo "Please enter the name of your config file, default is details.conf:" $config = read-host if ($config -eq "") { $config = "details.conf"} echo "Your config file is" $config Foreach ($i in $(Get-Content $config)){ Set-Variable -Name $i.split("=")[0] -Value $i.split("=",2)[1] } Echo "Using the following details from config file:" echo $vurl echo $username echo $location echo $template #Connect to the vcenter: Try{ Connect-VIServer $vurl -User $username -ErrorAction Stop } catch { $ErrorMessage = $_.Exception.Message Write-Host "Alert!!!! Connection to vCenter failed: $ErrorMessage" -ForegroundColor Red -BackgroundColor Yellow pause Write-Host "Please Restart the script" -ForegroundColor Red start-sleep -Seconds 5 break } Echo "Listing VMs:" $vmuser = ($username + "*") $vms = Get-VM -Name $vmuser echo $vms Echo "Listing templates:" $tlocation = ($location + "*") $templates = Get-template -location $tlocation echo $templates echo "Disconnecting:" disconnect-viserver