Grundlagen: VMs in Azure per PowerShell provisionieren

Wenn man neue VMs erstellt, kommt es drauf an, ob man eine neue VM durch eine Vorlage (Image) erstellt oder ob man eine VM erstellt, indem man einen registrierten Betriebssystemdatenträger (siehe auch Grundlagen: Datenträger per PowerShell auflisten und hinzufügen) verwendet. Bei Verwendung eines registriertes Betriebssystemdatenträgers muss das Betriebssystem fertig konfiguriert sein. Bei der Erstellung durch eine Vorlage dagegen ist das Betriebssystem noch nicht fertig konfiguriert. Wichtige Angaben wie der Benutzername und das Kennwort des Administrators fehlen noch. Zu diesem Zweck gibt es den PowerShell-Befehl Add-AzureProvisioningConfig. Der Befehl arbeitet in drei Ausführungen: für Stand-Alone Windows Server, Domain-Joined Windows Server und Linux-Server.

Es lohnt sich auch, die weiteren Parameter von Add-AzureProvisioningConfig anzusehen, da noch wesentlich mehr Optionen als den Admin betreffend konfiguriert werden können. Ein Auszug der Parameter habe ich weiter unter hinein kopiert.

Administrator festlegen

Schauen wir uns die drei Varianten an, den Zugang für den Administrator festzulegen. Alle drei Beispiele gehen davon aus, dass bereits eine VM-Konfiguration $vmConfig erstellt wurde.

$vmConfig = New-AzureVMConfig -ImageName $imageName -InstanceSize Small -Name $vmName -MediaLocation "https://$storageAccountName.blob.core.windows.net/$storageContainerName/$vmName.vhd"

Alleinstehender Windows Server

Add-AzureProvisioningConfig -Windows -AdminUsername $AdminUsername -Password $AdminPassword -VM $vmConfig

Windows Server, der einer Domäne angehört

Add-AzureProvisioningConfig -WindowsDomain -AdminUsername $AdminUsername -Domain $Domain -DomainPassword $DomainPassword -DomainUserName $DomainUsername -JoinDomain $JoinDomain -VM $vomConfig

Linux-Server

Add-AzureProvisioningConfig -Linux -LinuxUser $AdminUser -Password $AdminPassword -VM $vmConfig

Weitere Parameter von Add-AzureProvisioningConfig

Hier ein Auszug weiterer Parameter aus dem Hilfetext von Add-AzureProvisioningConfig.

  • -DisableGuestAgent <SwitchParameter>
    • To disable IaaS provision guest agent.
  • -CustomDataFile <String>
    • This parameter takes a file name as an argument. PowerShell will then base64 encode the contents of the file and send it along with the provisioning configuration information.  The file must be less than 64KB or the Azure API will not accept the request.
      • On Windows this data ends up in %SYSTEMDRIVE%AzureDataCustomData.bin as a binary file. 
      • On Linux, this data is passed to the VM via the ovf-env.xml file, which is copied to the /var/lib/waagent directory during provisioning. The agent will also place the base-64 encoded data in /var/lib/waagent/CustomData during provisioning.
  • -Windows <SwitchParameter>
    • Specify to create a standalone Windows provisioning configuration.
  • -AdminUsername <String>
    • Specifies the Administrator account to create.
  • -Password <String>
    • Specifies the password of the administrator account for the role.
  • -ResetPasswordOnFirstLogon <SwitchParameter>
    • If specified, forces the user to change their password on first logon.
  • -DisableAutomaticUpdates <SwitchParameter>
    • If specified, the configuration will have automatic updates disabled.
  • -NoRDPEndpoint <SwitchParameter>
    • If specified, create the virtual machine without a remote desktop endpoint.
  • -TimeZone <String>
    • Specifies the Microsoft Time Zone value to use to set the time zone for the virtual machine. Examples are: "Pacific Standard Time" and "Canada Central Standard Time".
  • -Certificates <CertificateSettingList>
    • Specifies a set of certificates to install in the virtual machine.
  • -EnableWinRMHttp <SwitchParameter>
    • Enables WinRM over http.
  • -DisableWinRMHttps <SwitchParameter>
    • Disables WinRM on https which is added by default.
  • -WinRMCertificate <X509Certificate2>
    • Certificate that will be associated with WinRM endpoint.
  • -X509Certificates <X509Certificate2[]>
    • X509 certificates that will be deployed to hosted service.
  • -NoExportPrivateKey <SwitchParameter>
    • Prevents the private key from being uploaded
  • -NoWinRMEndpoint <SwitchParameter>
    • Prevents the WinRM endpoint from being added
  • -Linux <SwitchParameter>
    • Specify to create a Linux provisioning configuration.
  • -LinuxUser <String>
    • Specifies the Linux administrative account name to create.
  • -DisableSSH <SwitchParameter>
    • If specified, the virtual machine is created with SSH disabled.
  • -NoSSHEndpoint <SwitchParameter>
    • If specified, create the virtual machine without an SSH endpoint.
  • -NoSSHPassword <SwitchParameter> 
  • -SSHPublicKeys <LinuxProvisioningConfigurationSet+SSHPublicKeyList> 
  • -SSHKeyPairs <LinuxProvisioningConfigurationSet+SSHKeyPairList>      
  • -WindowsDomain <SwitchParameter>
    • Specify to create a provisioning configuration for a Windows server joined to an Active Directory domain.
  • -JoinDomain <String>
    • Specifies the fully qualified domain name (FQDN) of the Windows domain to join.
  • -Domain <String>
    • Specifies the name of the domain of the account with permission to add the computer to a domain.
  • -DomainUserName <String>
    • Specifies the name of the user account with permission to add the computer to a domain.
  • -DomainPassword <String>
    • Specifies the password of the user account with permission to add the computer to a domain.
  • -MachineObjectOU <String>
    • Specifies the fully qualified name of the organizational unit (OU) in which the computer account is created.

Weitere Informationen

PowerShell: Azure-Automatisierung für Einsteiger (Microsoft Virtual Academy) Grundlagen: Azure & PowerShell: VMs erstellen (MSDN Blogs)

Grundlagen: Datenträger per PowerShell auflisten und hinzufügen (MSDN Blogs)