SHARE
TWEET

VMDeploymemt

mmannoni May 25th, 2019 (edited) 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Lokaler Admin definieren und Passwort abfragen
  2. $credential = Get-Credential -UserName $locadminusername -Message "Bitte Passwort eingeben für $locadminusername"
  3.  
  4.  
  5. # Erstellen der Ressourcegruppe
  6. New-AzResourceGroup -Name $paramvm.resourcegroup -Location $paramvm.location
  7.  
  8.  
  9. # Netz und das Subnet auslesen
  10. $vnet = Get-AzVirtualNetwork -Name $paramvnet.netname -ResourceGroupName $paramvnet.resourcegroupname
  11. $subnetconfig = Get-AzVirtualNetworkSubnetConfig -Name $paramvnet.privsubnetname -VirtualNetwork $vnet
  12.  
  13.  
  14. # Erstellen der Network Security Group mit Default Einstellungen
  15. $nsg = New-AzNetworkSecurityGroup -Name $paramvm.nsgname -ResourceGroupName $paramvm.resourcegroup  -Location  $paramvm.location
  16.  
  17.  
  18. # Erstellen der IP Konfiguration und des Netzwerkadapters
  19. # Binden des Adapters an das Subnet das definiert ist. Einbinden der NSG
  20. $ipconfig = New-AzNetworkInterfaceIpConfig -Name "IPConfigPrivate" -PrivateIpAddressversion IPv4 -PrivateIpAddress $paramvm.nicip -Subnetid $subnetconfig.Id
  21. $nic = New-AzNetworkInterface -Name $paramvm.nicname -ResourceGroupName $paramvm.resourcegroup -Location $paramvm.location `
  22. -NetworkSecurityGroupId $nsg.Id -IpConfiguration $ipconfig
  23.  
  24.  
  25. # VM Konfiguration zusammenbauen
  26. $vmconfig = New-AzVMConfig -VMName $paramvm.name -VMSize paramvm.size
  27. $vmconfig = Set-AzVMOSDisk -VM $vmconfig -Name $paramvm.osdisk -StorageAccountType $paramvm.storageaccounttype -Caching ReadWrite -CreateOption fromImage
  28. $vmconfig = Set-AzVMOperatingSystem -VM $vmconfig -Windows -ComputerName $paramvm.name -Credential $credential -ProvisionVMAgent
  29. $vmconfig = Set-AzVMSourceImage -VM $vmconfig -PublisherName $paramvm.publishername -Offer $paramvm.offer -Skus $paramvm.sku -Version latest
  30. $vmconfig = Add-AzVMNetworkInterface -VM $vmconfig -Id $nic.Id
  31.  
  32.  
  33. # VM erstellen
  34. New-AzVM -ResourceGroupName $vmconfig.resourcegroup -Location $vmconfig.location -VM $vmconfig -Verbose
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top