【问题标题】:PowerCLI Prompt for Server name for "Connect-VI Server"PowerCLI 提示“Connect-VI 服务器”的服务器名称
【发布时间】: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


【解决方案1】:

您可以通过执行 Read-Host 并将其存储在 Connect-VIServer cmdlet 可以使用的变量中来提示回答:

$vc = read-Host "vCenter Server?"
Connect-VIServer -Server $vc

【讨论】:

    猜你喜欢
    • 2017-03-02
    • 2013-06-16
    • 2018-10-01
    • 1970-01-01
    • 2013-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-19
    相关资源
    最近更新 更多