My question is a bit complex, so I will start with a short explanation of the context. The goal is to:
- Create a new Windows instance on the Google Cloud Platform
- Avoid the usage of the gcloud command line sdk and instead use the (REST) API
- Connect to the VM via powershell (not rdp)
Problem
There is no API to create a new windows account and password, like it exists for the gcloud command line:
gcloud compute reset-windows-password
But of course an user is needed to connect to the vm.
My ideas
I tried to use a startup script which creates a new user. The powershell script already works like expected on a running machine (as administrator):
$ADSIComp =[adsi]"WinNT://test-remote"
$NewUser = $ADSIComp.Create('User','test')
$NewUser.SetPassword(('S€cur3P@ssword'))
$NewUser.SetInfo()
$Group = [ADSI]"WinNT://test-remote/Administrators,group"
$Group.Add("WinNT://test,user")
Google cloud provides different types of startup scripts (see here). I tried to use sysprep-specialize-script-ps1, so it only runs once. (Is this correct?). To test if this works, I created a new windows instance on the google cloud dashboard. In the metadata section I inserted sysprep-specialize-script-ps1 as metakey and the script lines in brackets as value.
Result
I created a new user on the dashboard to login on the windows machine. But there is no user created by the above script. So my approach failed.
Open Questions
Can you see (conceptual or technical) mistakes in my process?
Is there any other way to achieve the specified goal?
Thank you!