Search code examples
azurebatch-filepsexecazure-virtual-network

How to copy files & run commands on remote Azure Win VM?


From my local Windows command prompt, I can copy files to local Windows machines, and run commands on the local Windows machines with psexec. (For example, launching .bat files). I can also start/stop and query services on the Windows machines, for example with sc \machineIP query (servicename).

I am learning to be able to do the same thing with a stock Windows machine hosted in Azure.

Having created a stock Windows Server VM in Azure from the command line, what more must I do? Currently on the Azure VM, for testing, I have:

  • Turned off the Firewall
  • Disabled simple file sharing wizard
  • Shared C, with permissions for 'everyone'
  • Started 'remote registry' service
  • Added registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\LocalAccountTokenFilterPolicy with value of 1 (hex)

I am able to RDP to the machine without a problem, with the given public IP address, username, and password.

I note that I cannot access: \publicIP\c$

And psexec returns 'The network path was not found. Make sure the default admin$ share is enabled on (publicIP)' when running the command:

psexec.exe \\(publicIP) -u(username) -p (password) -i 1 cmd /c c:\runMe.bat

Solution

  • In the Azure portal, navigate into the resource group where your VM resides. Select the 'Network Security Group' profile used by your VM (eg, yourVMnameNSG) -> edit -> add inbound security rules.

    eg:

    Name: psexec    
    Source: any
    Destination: any
    Service: Custom (Any/135)
    Action: allow
    

    Repeat for required services