0
votes

Imagine I have two Virtual Machines in my Azure subscription. From machine Foo, I’d like to be able to run Powershell commands and scripts on Bar under an admin account.

I will be using a Continuous Build Server on Foo, that when triggered it will create a (signed) script called go.ps1 in a shared directory accessible by both Foo and Bar. After that script is created, I want my CBS to have Bar copy that file to C:\scripts\go.ps1 and execute it, as if I were an Admin sitting at Bar. I’ve done something similar in the past on physical machines using psexec. I assume there is something similar for Azure VMs.

2
You can also use invoke-command to execute remote script or .ps1 file.Ivan Yang

2 Answers

0
votes

If the virtual machines are on the same VNet using Azure provided DNS then psexec should work.

0
votes

Generally, you can do something similar in the past on physical machines using PsExec. About Azure VMs, you could ensure the network connection is working between the two VMs. If they are in the different VNets, you could peer the VNets with each other. If they are in the same VNet, there are by default NSG inbound rule to allow any port from virtual network to another virtual network, so you just need to open the PSEXEC port 445 in the firewall inside the VM such as Windows Firewall.

This works for me. Enable the port 445 in the inbound rule of windows firewall with the private profile. I can run PsExec on the VM 10.0.0.4 to open the CMD in the VM 10.0.1.6. enter image description here

enter image description here

Alternatively, there are many methods for you to run scripts on the Azure VM. Feel free to let me know if you are anything unclear in the reply.