PowerShell/VMware/Deployment/deploy_vms_NEW.ps1

35 lines
2.9 KiB
PowerShell
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#Connect-VIServer vmware.asl.local
cls
$deploy_host = "kfhnpxpes203.asl.local"
$templatename = "DisWeb_IIS_Template"
#Hier MUSS der Datastore angegeben werden.
$dscluster = "Datastorename!!!"
Write-Host "Getting VMs to deploy"
$vms_to_deploy = $null
#HIER DEN PFAD ZUR CSV DATEI MIT DEN VM DETAILS ANGEBEN
$vms_to_deploy = Get-Content -Path e:\disweb_vms.csv
Write-Host "Building VMs"
foreach ($singlevm in $vms_to_deploy){
if ($singlevm -ne $null){
Write-Host selected Deploy Host $deploy_host
$vm = $singlevm.Split(";")
$vmname = $vm[0]
$ip1 = $vm[1]
$gateway1 = $vm[2]
$subnet1 = $vm[3]
$DNSSrv1a = $vm[4]
$DNSSrv1b = $vm[5]
Write-Host "Getting VM Customization"
$vm_customization = Get-OSCustomizationSpec "KFH_DisWeb_IIS_SPLA_W2K12R2-STD-MASS-singleNIC"
Write-Host "Setting VM Customization"
Get-OSCustomizationNicMapping -OSCustomizationSpec "KFH_DisWeb_IIS_SPLA_W2K12R2-STD-MASS-singleNIC" | where { $_.Position -eq '1'} | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $ip1 -SubnetMask $subnet1 -DefaultGateway $gateway1 -Dns $DNSSrv1a,$DNSSrv1b
Write-Host "Creating VM" $vmname -BackgroundColor Green
New-VM -Template $(Get-Template $templatename) -Name $vmname -vmHost $deploy_host -Datastore $dscluster -DiskStorageFormat Thick -OSCustomizationSpec $vm_customization -location "deployment" -RunAsync
}
else {
Write-Host "No VMs to deploy in file" -BackgroundColor Red
}
}