【发布时间】:2016-11-22 18:37:17
【问题描述】:
我正在尝试使用 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
我正在尝试确定是否有办法让 PowerCLI 脚本在脚本“Connect-VIServer -Server $vcenter_srv”中出现时使用“Connect-VIServer”命令提示输入服务器名称,然后继续从 CSV 文件中提取剩余的值。
感谢您提供的任何信息,
【问题讨论】:
-
如果你不告诉它连接哪个服务器你会得到什么?
标签: powershell automation vmware powercli