Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6829
  • Last Modified:

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!!!
0
learn2earn
Asked:
learn2earn
  • 6
  • 4
2 Solutions
 
footechCommented:
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

0
 
learn2earnAuthor Commented:
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?
0
 
footechCommented:
Now will the "Invoke-Command work on a ShortCut to the MSI file on the server"?
I don't know for certain... never tried.  One way for you to find out.  Keep in mind that sometimes trying to perform an unattended installation can be different than just running the .MSI through a GUI (which is why I am calling msiexec which references the actual .MSI file).  But if the shortcut points to a file on another machine I'm certain you will encounter problems.

Also with your code I do not see the path to where compters or the msi is being stored.
I don't think I understand your question.  You can reference whatever path you need.  If your computers.txt file is in c:\temp, well, you've already shown you know how to read the file with the path explicitly defined.  In my example I just showed how you could run it with the files in the current working directory.  Since working with remote filesystems within a remote PS session involves other complications (search for kerberos second hop and credssp), which is a whole other topic I'll avoid it for this question and just use local paths inside the remote session.

$deploy = {
    Set-Location "c:\temp"
    & msiexec.exe /I installwizard.msi /quiet 
}

$computers = Get-Content "c:\whatever\path\you\want\computers.txt"
foreach ($comp in $computers)
{
   Copy-Item -path \\server\share\installwizard.msi -Destination \\$comp\c$\temp
   $session = New-PSSession -ComputerName $comp
   Invoke-Command -Session $session -ScriptBlock $deploy
}

Open in new window

After the installation has completed you will probably want to do another foreach loop through the computers list to remove the .MSI from each machine with Remove-Item.  And you can clean up all the now-unneeded sessions with Get-PsSession | Remove-PsSession.
0
Worried about phishing attacks?

90% of attacks start with a phish. It’s critical that IT admins and MSSPs have the right security in place to protect their end users from these phishing attacks. Check out our latest feature brief for tips and tricks to keep your employees off a hackers line!

 
learn2earnAuthor Commented:
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)
0
 
footechCommented:
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.
0
 
learn2earnAuthor Commented:
I will test it on Monday as my Day is done here at work!

Thank you, and I will keep you posted.
0
 
footechCommented:
No problem.  If you have any issues I may not be able to respond until the following week.
Happy Holidays!
0
 
learn2earnAuthor Commented:
Below is what I came up with using the "help (get-help)" commands to get it to work.

I did use your variables to get it started.


$computers = Get-Content "c:\temp\computers.txt"
$rs = Get-PSSession

######
## Functions
################

Function PushMSI {
 Write-Host "------------------------------------------------"
 Write-Host "This will copy the MSI file from localhost c:\temp\"
 write-Host "------------------------------------------------"
 Write-Host ""
 Write-Host ""
 foreach ($comp in $computers)
{
   Copy-Item -path "c:\temp\UPS Client Update.msi" -Destination \\$comp\c$\temp
   
}
}

Function RemoteConnect
{
 Write-Host "------------------------------------------------"
 Write-Host "This will establish a PSSession with all computers in c:\temp\computers.txt"
 write-Host "------------------------------------------------"
 Write-Host ""
 Write-Host ""
Get-Content C:\temp\computers.txt | New-PSSession -ThrottleLimit 50
}

Function InstallMSI
{
 Write-Host "------------------------------------------------"
 Write-Host "This will Install UPS Update on all computers with an Established PSSession"
 write-Host "------------------------------------------------"
 Write-Host "After the Install PSSessions will be removed"
 Write-Host ""
Invoke-Command -Session $rs -ScriptBlock {invoke-item "c:\temp\UPS Client Update.msi"}
}

Get-PSSession | Remove-PSSession

Thank you for your help with getting me started in the right direction!!
0
 
learn2earnAuthor Commented:
_
0
 
learn2earnAuthor Commented:
I did some reading and found what I was looking for by using the PowerShell Help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now