Solved

PowerShell - Remote Software Install

Posted on 2013-12-17
10
5,635 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
  • 6
  • 4
10 Comments
 
LVL 39

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 39

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
 
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 39

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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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 39

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
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 walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now