I am trying following--> Creating GCE instance via gcloud cmds
- As a metadata I am providing ps1 scripts which is creating User and adding to required domain
- Once user created I need to use that user credential and run few commands as administator
This all needs to be done via Metadata scripts (Startup script powershell script)
I know we can directly run basic cmds without admninistrator user directly in metatdata script.
How to use script via metadata
Tried below
Created job which having code to create user and loging with administrative access
Use Start-process with runas passing credential as PS object
but not able to connect using those credentials
Any help appreciated!!
Here is what I did to achieved this :
We can use GCP system preparation and startup script to achieve our goal.
In main terraform create Unix VM
Prepared Unix script which is doing all below steps.
a. write code to setup following using gcloud
b. System preparation script. (We are preparing this ps1 PowerShell script in above .sh script by using cat cmd)
Setup ps1 script to make local user as administator ([adsi]"WinNT).
Disable consent prompt behavior via windows registry
Install ADFS and other nessesary tools.
c. Startup script (PowerShell script)
Pass credentials in this script which we created in 2.a (Setup password to AD domain using gcloud) to add win VM to domain created earlier.
Enable CredSSP
login to window VM using above cred, you can refer PowerShell cmds mentioned below
You can write code to achieved your task as you are logged in to win VM as administrator.
d. Once above two script done.
Ref link:--
https://cloud.google.com/managed-microsoft-ad/docs/deploy-adfs
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/invoke-command?view=powershell-7.3
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/new-pssession?view=powershell-7.3
https://learn.microsoft.com/en-us/powershell/module/microsoft.wsman.management/enable-wsmancredssp?view=powershell-7.3
https://cloud.google.com/compute/docs/instances/startup-scripts/windows
Note: You need to install all necessary tools to setup domain configuration in win VM. like ADFS tool etc.