PowerCLI提示服务器名称为“Connect-VI服务器”
问题描述:
我试图使用PowerCLI脚本基于CSV文件创建虚拟机。那我一起工作的当前的代码具有“连接-VIServer”硬编码在脚本“$ vcenter_srv =‘vcenter.seba.local’”的变量:PowerCLI提示服务器名称为“Connect-VI服务器”
$ScriptRoot = Split-Path $MyInvocation.MyCommand.Path
$csvfile = "$ScriptRoot\vms2deploy.csv"
$vcenter_srv = 'vcenter.seba.local'
$timeout = 1800
$loop_control = 0
$vmsnapin = Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
$Error.Clear()
if ($vmsnapin -eq $null)
{
Add-PSSnapin VMware.VimAutomation.Core
if ($error.Count -eq 0)
{
write-host "PowerCLI VimAutomation.Core Snap-in was successfully enabled." -ForegroundColor Green
}
else
{
write-host "ERROR: Could not enable PowerCLI VimAutomation.Core Snap-in, exiting script" -ForegroundColor Red
Exit
}
}
else
{
Write-Host "PowerCLI VimAutomation.Core Snap-in is already enabled" -ForegroundColor Green
}
if ($env:Processor_Architecture -eq "x86") {
#Connect to vCenter
Connect-VIServer -Server $vcenter_srv
我想,以确定是否有一种方法可以使PowerCLI脚本在脚本“Connect-VIServer -Server $ vcenter_srv”中出现时使用“Connect-VIServer”命令提示输入服务器名称,然后继续从CSV文件中提取剩余值。
感谢您可能提供的任何信息,
答
你可以做一个读主机并将其存储在一个变量,它的Connect-VIServer cmdlet的可以如下使用提示的aswer:
$vc = read-Host "vCenter Server?"
Connect-VIServer -Server $vc
如果你不告诉它连接哪台服务器,你会得到什么? – TessellatingHeckler