I want to create users in windows server on google cloud during instance creation. Searched in google cloud documentation and other sites but could not find answers. I am aware of startup scripts but those are great when you want to do something every time machine boots up. Please help.
-
Do you want to sync users from AD (Windows server I assume) as an identity providers? – NeatNerd Nov 09 '20 at 20:52
-
No. At the moment, my requirement is to be able to create instance with 2-3 users of my choice. – ManWarrior Nov 10 '20 at 09:24
-
an instance of Windows server, correct? – NeatNerd Nov 10 '20 at 09:25
-
My requirement is to be able to run few commands (like useradd or net user) when the instance is being created. This will save the time spent in login to all machines one by one and running 2-3 commands per user. – ManWarrior Nov 10 '20 at 09:33
-
Windows and Linux both – ManWarrior Nov 10 '20 at 09:33
1 Answers
You can use GCP startup script to do it. Please have a look at the documentation Running startup scripts. For example, you can easily add a user John
and add him to the group Remote Desktop Users
by using metadata:
and, as a result, you'll be able to login via RDP to your VM instance with login John
and password fadf24as.FD*
.
By default such script will be executed during each start cycle of VM instance:
Compute Engine lets you create and run your own startup scripts on your virtual machine (VM) instances to perform automated tasks every time your instance boots up.
To change this default behavior you can add there additional step like creating some folder or file and use them as a flag: if folder or file already exist than rest part of the script should be skipped. In such case PowerShell looks more suitable than cmd, final script could be uploaded from Google Cloud Bucket.

- 4,287
- 2
- 16
- 29