PowerCLI提示“Connect-VI Server”的服务器名称(PowerCLI Prompt for Server name for “Connect-VI Server”)
我正在尝试使用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文件中提取的值。
感谢您提供的任何信息,
I am attempting to use a PowerCLI script to create Virtual Machines based off of a CSV file. The current code that I am working with has the 'Connect-VIServer' hard-coded as a variable in the script "$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_srvI am trying to determine if there is a way to cause the PowerCLI script to prompt for the server name with the 'Connect-VIServer' command when it occurs in the script "Connect-VIServer -Server $vcenter_srv" and then continue with the remaining values pulled from the CSV file.
Thank you for any information you may provide,
您可以通过执行读取主机并将其存储在Connect-VIServer cmdlet可以使用的变量中来提示输入aswer,如下所示:
$vc = read-Host "vCenter Server?" Connect-VIServer -Server $vcYou can prompt for an aswer by doing a Read-Host and storing it in a variable which the Connect-VIServer cmdlet can use as below:
$vc = read-Host "vCenter Server?" Connect-VIServer -Server $vc
推荐本站淘宝优惠价购买喜欢的宝贝:
本文链接:https://hqyman.cn/post/3403.html 非本站原创文章欢迎转载,原创文章需保留本站地址!
休息一下~~