Executing CMD file remotely

I am trying to find a way to execute a command, located on a network share, from a remote workstation.

The scenario; I have a new VM server we will call newserverone. If I log into newserverone, I can execute the cmd file located on a network share //storage/installs/monitor.cmd by simply opening up explorer and typing in //storage/installs/monitor.cmd. What I would like to do is write a script that I could run on my workstation that would execute this in the same manner as it does via the gui. I ran into similar problem with trying to run a msi file but I found a workaround for it. (see below) The problem is I cannot copy everything from the network share for the monitor.cmd install.

For the msi install;

Copy-Item -Path "\\storage\AntiVirus\WebRoot-Installers\Windows\Webroot.msi" -Destination \\newserverone\c$\installs
Invoke-Command -ComputerName newserverone -Credential domain\adminuser -ScriptBlock { Msiexec /i \\newserverone\C$\installs\Webroot.msi /log C:\MSIInstall.log }
Start-Sleep -Seconds 33
Remove-Item -Path \\newserverone\C$\installs\Webroot.msi

If someone also has a better way to deal with this msi install, I would love to hear about that as well. Any help is greatly appreciated. Thank you in advance.


You are invoking the command on the other system, so write the code as if you were sitting at the other system. You should be able to run what is in the scriptblock and install the software:

$sb = {
    #Copy the file locally
    Copy-Item -Path "\\storage\AntiVirus\WebRoot-Installers\Windows\Webroot.msi" -Destination 'C:\Installs\AntiVirus'

    #Create a logfile path
    $logFile = 'C:\Installs\AntiVirus\webroot-{0}.log' -f (Get-Date -Format yyyyMMddTHHmmss)
    $MSIArguments = @(

    #Start the installer and wait until complete
    Start-Process -FilePath "msiexec.exe" -ArgumentList $MSIArguments -Wait -NoNewWindow 

    #Remove the directory
    Remove-Item -Path 'C:\Installs\AntiVirus' -Force


Invoke-Command -ComputerName newserverone -Credential domain\adminuser -ScriptBlock $sb

These commands should be wrapped with try\catch to ensure step 1 completes before the step 2 and so on and so forth, but the above code should be close. There are many examples of installing software and MSI’s with Powershell that you can reference.

Thank you for the response. I need to clarify one thing about my question. While I was able to make the msi install work properly by copying it to the new server but I cannot get the “.cmd” installer to work properly. It would be even better if I could install from a network share instead of copying the entire software down to the server. Unless that is my only option.