Link to home
Start Free TrialLog in
Avatar of A Edwards
A Edwards

asked on

PowerShell - Remote Software Install

Hello,

Here is what I have to do manually every time. Log into every computer and connect to a "Share" on my network that has a shortcut to run this "MSI" file.

1. I log in and I run the MSI file
2. log off and let the user log back in to run the program

I want to automate this process using PowerShell.  

here is the location to the file - "\\10.0.2.10\Production\TBA Client\TBA client Update.msi"
I have my computer names in a txt file. So I can use "Get-Content" command.

HELPPP!!!
Avatar of footech
footech
Flag of United States of America image

I've been able to do this with PowerShell Remoting (has to be enabled on all the target computers).
Steps are:
- create new pssession for target machine
- If needed by the installation process, copy the file(s) to the target machine via UNC path
- Run the .MSI file.
- You may want/need to perform some cleanup of files, and/or unneeded pssessions.
Here's the core code that would actually run the .MSI.
$computers = Get-Content computers.txt
foreach ($comp in $computers)
{
   $deploy = { & msiexec.exe /I installwizard.msi /quiet }
   $session = New-PSSession -ComputerName $comp
   Invoke-Command -Session $session -ScriptBlock $deploy
}

Open in new window

Avatar of A Edwards
A Edwards

ASKER

Thanks for the info,

Now will the "Invoke-Command work on a ShortCut to the MSI file on the server"?
Also with your code I do not see the path to where compters or the msi is being stored.

I can store it in c:\Temp\  

then it would look like this

$computers = Get-Content 'c:\Temp\computers.txt'
$m = "c:\temp\software install.lnk'

can you make it a little more clear?
SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Okay so here is what works for me.

$computers = Get-Content "c:\temp\computers.txt"
foreach ($comp in $computers)
{
   Copy-Item -path "T:\TBA Client\TBA Client Update.msi" -Destination \\$comp\c$\temp
{

That part actually does what I want.  Which is copy the files to the TEMP directory.
Now I want to Establish a PSSession with all those computers in my $computers variable.
I want to (invoke-item  "c:\temp\*msi") on all those computers to run the msiexe.exe

I have tested it out on one machine PSSession and it works. I just do not know how to get multiple PSSessions to execute the (invoke-item)
If Invoke-Item works for you, then you can just substitute that for line 3 in my post above.  The code I posted creates a new session and then uses that with Invoke-Command to run all the commands that are stored in the $deploy variable.
I will test it on Monday as my Day is done here at work!

Thank you, and I will keep you posted.
No problem.  If you have any issues I may not be able to respond until the following week.
Happy Holidays!
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
_
I did some reading and found what I was looking for by using the PowerShell Help.