diff --git a/pkg/cloud/azure/services/virtualmachines/virtualmachines.go b/pkg/cloud/azure/services/virtualmachines/virtualmachines.go
index 7378cb2fe7e..4057995f415 100644
--- a/pkg/cloud/azure/services/virtualmachines/virtualmachines.go
+++ b/pkg/cloud/azure/services/virtualmachines/virtualmachines.go
@@ -34,6 +34,34 @@ import (
"sigs.k8s.io/cluster-api-provider-azure/pkg/cloud/azure/services/networkinterfaces"
)
+const (
+ // winAutoLogonFormatString is the format string used to create the AutoLogon
+ // AdditionalUnattendContent configuration for Windows machines.
+ winAutoLogonFormatString = `
+ %s
+
+ %s
+
+ true
+ 1
+ `
+
+ // winFirstLogonCommandsString is the string used to create the FirstLogonCommands
+ // AdditionalUnattendContent configuration for Windows machines.
+ winFirstLogonCommandsString = `
+
+ Copy user data secret contents to init script
+ cmd /c "copy C:\AzureData\CustomData.bin C:\init.ps1"
+ 11
+
+
+ Launch init script
+ powershell.exe -NonInteractive -ExecutionPolicy Bypass -File C:\init.ps1
+ 12
+
+ `
+)
+
// Spec input specification for Get/CreateOrUpdate/Delete calls
type Spec struct {
Name string
@@ -126,6 +154,20 @@ func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error {
if compute.OperatingSystemTypes(vmSpec.OSDisk.OSType) == compute.Windows {
osProfile.WindowsConfiguration = &compute.WindowsConfiguration{
EnableAutomaticUpdates: to.BoolPtr(false),
+ AdditionalUnattendContent: &[]compute.AdditionalUnattendContent{
+ {
+ PassName: "OobeSystem",
+ ComponentName: "Microsoft-Windows-Shell-Setup",
+ SettingName: "AutoLogon",
+ Content: to.StringPtr(fmt.Sprintf(winAutoLogonFormatString, *osProfile.AdminUsername, *osProfile.AdminPassword)),
+ },
+ {
+ PassName: "OobeSystem",
+ ComponentName: "Microsoft-Windows-Shell-Setup",
+ SettingName: "FirstLogonCommands",
+ Content: to.StringPtr(winFirstLogonCommandsString),
+ },
+ },
}
} else if sshKeyData != "" {
osProfile.LinuxConfiguration = &compute.LinuxConfiguration{