Copy Folder to Multiple Workstations then Invoke Command

I need help invoking a command but I need it to pull the info from $computers and hopefully run a script from a subfolder within the folder copied by using the recurse switch perhaps? I dont need to automate the actual script name GoogleEarthInstall.bat since this needs to be set manually since we usually have multiple scripts in the folder ie install, uninstall, some are bat and some are just ps1.

Also need the folder to copy to the machine first before the invoke command executes the batch file.

A progress indicator would be cool as well!

 

# This file contains the list of servers you want to copy files/folders to

$computers = gc "C:\Workstations.txt"

# This is the file/folder(s) you want to copy to the servers in the $computer variable

$source = "C:\Google Earth"

# The destination location you want the file/folder(s) to be copied to

$destination = "C$\Applications\"

foreach ($computer in $computers) {

if ((Test-Path -Path \\$computer\$destination)) {

Copy-Item $source -Destination \\$computer\$destination -Recurse {

Invoke-Command -Command {".\GoogleEarthInstall.bat"}

} else {

"\\$computer\$destination is not reachable or does not exist"

}

}

ok, where you are stuck. ONe thing I notices is that you are just priting “.\GoogleEarthInstall.bat” by keeping this in quotes. No need to put it in quotes, give the absolute path, it will just execute.