Solved

PowerShell - Remote Software Install

Posted on 2013-12-17
10
6,215 Views
Last Modified: 2013-12-31
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
Comment
Question by:learn2earn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 40

Expert Comment

by:footech
ID: 39727579
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
 
LVL 2

Author Comment

by:learn2earn
ID: 39727722
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
 
LVL 40

Assisted Solution

by:footech
footech earned 500 total points
ID: 39728720
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 2

Author Comment

by:learn2earn
ID: 39732655
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
 
LVL 40

Expert Comment

by:footech
ID: 39732710
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
 
LVL 2

Author Comment

by:learn2earn
ID: 39732916
I will test it on Monday as my Day is done here at work!

Thank you, and I will keep you posted.
0
 
LVL 40

Expert Comment

by:footech
ID: 39733072
No problem.  If you have any issues I may not be able to respond until the following week.
Happy Holidays!
0
 
LVL 2

Accepted Solution

by:
learn2earn earned 0 total points
ID: 39740502
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
 
LVL 2

Author Comment

by:learn2earn
ID: 39740592
_
0
 
LVL 2

Author Closing Comment

by:learn2earn
ID: 39747886
I did some reading and found what I was looking for by using the PowerShell Help.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question