I have a PowerShell script, that run's at user log in on one VM (00000281): Get-Content C:/sample.txt -TotalCount 1) | Set-Content C:\sample.txt
To execute the script automatically I have created a .cmd file and placed it in the following folder:
C:\Users\vs_domadmin\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
The above VM(00000281) resides in my infra VM's cluster which contains four other Vm's (infra servers). I have a total of four servers, which I would like that script to run as well.
00000281, 00000282, 00000283, 00000284
My script is running for the moment only on the 00000281. Here is the trick: I need that script from 00000281 to execute also on the rest of the infra servers 00000282, 00000283, 00000284, knowing that the script will be stored only on my first infra server 000002821. I believe that giving the script some conditions and outlining the path of the other 3 VMs in VM (00000281) should do the work correct>
VM 00000282, 00000283, 00000284 is considered as a remote machine w.r.t the current user in vm 00000281.
You have to run the script in the machine itself using the powershell Remote process of the same machine by configuring the 4 machines to run remote powershell script.
This done by enabling every machine to run the powershell remote service WinRM
For step by step details:
How to Run PowerShell Commands on Remote Computers
Modify the script in vm 00000281, add this as last line:
Invoke-Command -ComputerName 00000282, 00000283, 00000284 -FilePath path_to_script_file.ps1
In this way you run concurrently the same script in all machines.
Login user should have a permission in these machines.