Terraform GCP: Run PowerShell in Windows instance on create - powershell

I have made a simple Terraform manifest that successfully initiates a Windows 2016 instance in GCP. As a next step I would like to execute a Powershell script to further configure and install software in the Windows instance.
I can not for my life find any example on how to execute a remote script through Terraform in a Windows GCP instance. For Linux instances it seems pretty straight forward, but how is it supposed to be done for Windows? Does anyone know any examples?
Any thoughts or ideas are much appreciated, thanks!

I had the same situation one month ago in the Oracle cloud. (I think the process is the same for all cloud providers.)
My situation: I have to run the winrm script to allow the communication from ubuntu to windows 2016 server to run the Ansible playbooks.
You can find the answer below.
https://github.com/terraform-providers/terraform-provider-oci/tree/master/examples/compute/windows.
I put my Powershell script (winrm) in the "userdata" folder and update the same in winrm.tf file. That's it.

Related

google cloud notebook instance run script not in startup

I have a notebook instance with a notebook file. I use the instance's startup script to run this notebook file using papermill.
I want the notebook file to be run only when I remotely start the instance, and not from google cloud console.
I'd like to know if one of these is possible, or if there's another solution:
1 - The script will detect that the instance was started from the dashboard.
2 - I will remove the startups script and use another script that can be run by a remote command.
3 - The shutdown script will remove the startup script.
Script definition is kept under /var/run/google.startup.script for the scenarios mentioned:
Seems complicated detect if the instance was started from the dashboard.
Is feasible to delete the startup script mentioned earlier, and run your own script remotely.
Delete the script.
Before to delete the scrip I suggest you to make a backup of it in case of any issue arises for delete it, also keep in mind that AI Platform Notebooks is a managed service, any admin configuration could cause potential issues in your instance, be careful when deleting or modifying the startup script.
My advise will be actually run a notebook via a Scheduler system, I posted here the multiple options: GCP run a prediction of a model every day

ARMClient.exe not working in azure powershell workflow (hydrid)

I am trying to execute the ARMClient.exe from my Azure Powershell Workflow runbook on Hydrid worker.
Its throwing me the folloing error:
Cannot find the 'ARMClient.exe' command. If this command is defined as a workflow, ensure it is defined before the workflow that calls it. If it is a command intended to run directly within Windows PowerShell (or is not available on this system), place it in an InlineScript: 'InlineScript { ARMClient.exe }'
I have followed https://azure.microsoft.com/en-in/blog/leveraging-the-oms-search-api-in-an-azure-automation-runbook/
post step by step.
Can anyone help me resolve this error.
Thanks in Advance!
I restarted the Hybrid worker VM, and it started to recognize the command ARMClient.exe from azure runbook!
Silly of me, I should have restarted the VM before posting the question here :(
Did you do the Hybrid worker setup correctly?
It looks like from the error message that it cannot locate the ARMClient.exe, usually meaning it's not installed / cannot be resolved in the $env:path (paths on the machine).
Did you install chocolatey and the ArmClient package (using choco install armclient) on the worker? Have you verified that the Armclient is installed?
For details installing chocolatey see : https://chocolatey.org/
For details on installing the armclient : https://github.com/projectkudu/ARMClient

Powershell WinRM (WS-manager) service is not running after enabling it in group policy

I need to run remote powershell commands on a 2008 R2 server, so i enabled WinRM using the group policy
but then when i go into windows services to view the running services, the Windows Remote Management (WS-Management) is not on the list
so then when i try to run powershell commands that would setup WinRM
It says that the service is not running, thus i cant register the configuration; which is what i really need since i need to run powershell commands as PS version 2 and not version 3
has anyone encountered this before? does anyone have any idea of where to start looking?
thanks
First, you don't need WinRM or PowerShell remoting to run version 2.0. You just invoke powershell with that version:
powershell.exe -Version 2.0
As to your problem, I am not sure why the service is missing. Since you installed WMF 3/Powershell 3 yourself (I'm assuming, because it's 2008 R2), maybe you can try reinstalling or repairing it? Are there any messages in the event log? I admit I have never seen this before.
Have you used an installer for 2008 R2 that was customized or cut down, like the person who asked this question?

Creating Powershell script for VMWare using veeam

I am trying to create a script to automate the Veeam backup using PowerShell.
I know in the free version I only have 2 options (Veeamzip and Quick Backup).
I have a Drobo on the network with the share setup and accessible.
I have gone into all the VMWare Hypervisors and created an account with the proper permissions to run a backup.
I am down to creating the syntax for running the backup.
I am confused when I look at their document. I am not sure if I am supposed to use a copy, replication, a backup job, or what.
If I can get the initial syntax to run a backup of one machine I know I can build the script.
Any information would be greatly appreciated.
This can not be done with this version of VMWare.

Deployment not in a domain - psexec.exe or powershell remoting

I am working on an automated deployment process for a web application. The deployment will need to:
Deploy DB changes to database using sqlpackage.exe
Deploy reporting services reports to the reports server using the web service
Deploy web app to web server(s)
Deploy fonts for reports
among other things
The first two are reasonably straightforward to run from the web server, as the web service and db are contactable, and the tools to deploy run over the network.
From reading it appears that powershell remoting should be the way to go, and internally this would not be a problem. However when deploying to production, this will be being carried out in a datacentre, where the machines (2web, 1db) are not on a domain at all. I'd like to come up with a generic process that can run both internally and externally with the appropriate configuration. Powershell remoting, with machines not in a domain appears to require a fair bit of configuration using https etc., as NT credentials can't be validated.
Should I battle out configuring powershell remoting, or would configuring this to just use psexec to execute a powershell script directly on the remote machien, copying the deployment artifacts to a drop folder on the remote machine be the best way to go?
psexec seems to "just work". It appears powershell remoting comes with a lot more pain.
Why not use psexec then? You can restrict it's role to just getting you on to the remote machine, and not let it infect your scripts. I have not attempted to get ps remoting working on a non-domain, but it general I have found it to be fairly high effort to get going. Psexec, as you say, can often be simpler.
Excuse the peddling, but the open source framework I helped build called PowerUp essentially does all this for your. It uses a model in which the powershell (well psake) scripts can move execution to another machine by calling a specific function. This can either be done with powershell remoting or psexec - you wouldn't need to change the script, it just requires a setting per environment to say which you would like to use.
Check other the sample at https://github.com/AffinityID/PowerUpSamples/tree/master/SimpleWebsite.
Hopefully that shows you enough, but if not let me know and we can go into more detail.