Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Remote program execution for multiple servers

$
0
0

Hello,

I am trying to copy a file and execute on numerous servers remotely. the file copies successfully but unfortunately the exe doesn't executes. Can someone please identify where it goes wrong. below is script

#Variables

$computername=Get-Content servers2.txt

$sourcefile="C:\Users\username1\Downloads\app\folder2\app.exe"

$destinationFolder="\\$computer\C$\admin\scripts"

#This section will install the software

foreach ($computerin$computername)

{

       #It will copy $sourcefile to the $destinationfolder. If the Folder does not exist it will create it.

 

   if (!(Test-Path-path$destinationFolder))

    {

       New-Item$destinationFolder-TypeDirectory

    }

   Copy-Item-Path $sourcefile-Destination $destinationFolder}

   Invoke-Command-ComputerName$computer-ScriptBlock {Start-Process"C:\Admin\Scripts\app.exe"}

Thank you,

 


MYM


Viewing all articles
Browse latest Browse all 15028

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>