Powershell 在CSV中某些列的值前面添加变量
我目前正在尝试创建一个简单的Powershell 在CSV中某些列的值前面添加变量,powershell,csv,powercli,Powershell,Csv,Powercli,我目前正在尝试创建一个简单的导入Csv,以将vm来宾从模板克隆到vcenter中的esx主机 在开始克隆之前,我想询问vm来宾将属于的站点的名称。站点名称是vm来宾将拥有的名称的一部分,也是来宾将被放入的foldername的一部分 Connect-VIServer -Server vcenter.localdomain.com -user * $Site = Read-Host "What is the name of the Site you want to install (i.e. S
导入Csv
,以将vm来宾从模板克隆到vcenter中的esx主机
在开始克隆之前,我想询问vm来宾将属于的站点的名称。站点名称是vm来宾将拥有的名称的一部分,也是来宾将被放入的foldername的一部分
Connect-VIServer -Server vcenter.localdomain.com -user *
$Site = Read-Host "What is the name of the Site you want to install (i.e. Site01)?"
Import-Csv "C:\guests.csv" -UseCulture | %{
New-vm -Name $_."Server Name" -VMhost $_."ESX Host" -Template $_.Template -Datastore $_.Datastore -Location $_.Folder
}
如何/在何处输入变量$Site
,使其位于$..Server Name“
和$..Folder
?您可以使用格式字符串:
您可以使用格式字符串:
工作起来很有魅力。谢谢工作起来很有魅力。谢谢
Connect-VIServer -Server vcenter.localdomain.com -user *
$Site = Read-Host "What is the name of the Site you want to install (i.e. Site01)?"
Import-Csv "C:\guests.csv" -UseCulture | %{
New-vm -Name ('{0}{1}' -f $Site, $_."Server Name") -VMhost $_."ESX Host" -Template $_.Template -Datastore $_.Datastore -Location ('{0}{1}' -f $Site, $_.Folder)
}