我试图使用一个PowerCLI脚本来创建基于CSV文件的虚拟机。我正在使用的当前代码将'Connect-VIServer‘硬编码为脚本"$vcenter_srv =’vcenter.seba.local‘“中的变量:
$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我试图确定是否有一种方法可以在脚本"Connect-VIServer -Server $vcenter_srv“中使用'Connect-VIServer‘命令提示服务器名,然后继续使用从CSV文件中提取的其余值。
感谢您提供的任何信息,
发布于 2016-11-22 19:20:30
您可以通过执行读主机并将其存储在可以使用的变量中来提示aswer,如下所示:
$vc = read-Host "vCenter Server?"
Connect-VIServer -Server $vchttps://stackoverflow.com/questions/40749253
复制相似问题