PoshCode Logo PowerShell Code Repository

Remote Install by AlphaSun 12 months ago
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/6298"></script>download | new post

This script allows an administrator to install software from either a local folder on their administration PC or from a network share. Target computers to receive the installation are defined ahead of time in a text file.

The specified installer is copied locally to the C:\TEMP folder of each of the target computers and an installer process is initiated locally on each target. Arguments for the installer file can be provided and are optional.

  1. function Install-Software{
  2. #.Synopsis
  3. #  Install software from a UNC path to a remote computer
  4. #.Description
  5. #  This script allows an administrator to install software from either a local folder on their administration PC or
  6. #  from a network share. Target computers to receive the installation are defined ahead of time in a text file.
  7. #
  8. #  The specified installer is copied locally to the C:\TEMP folder of each of the target computers and an installer
  9. #  process is initiated locally on each target. Arguments for the installer file can be provided and are optional.
  10. #.Parameter Targets
  11. #  Input file of target computers. The file should be a plain text file with one target system on each line.
  12. #.Parameter Install
  13. #  The UNC path to the executable file. Arguments are listed separately and should not be specified here.
  14. #.Parameter Arguments
  15. #  Arguments for the executable.
  16. #.Example
  17. #  Install-Software -Targets .\computers.txt -Install "\\MyServer\MyShare\Folder\setup.exe" -Arguments "/V/qn NoRestart"
  18. #
  19. #  Description
  20. #  -----------
  21. #  Copies setup.exe from \\MyServer\MyShare\Folder to each of the target computers listed in computers.txt and initiates
  22. #  setup.exe with the arguments "/V/qn NoRestart".
  23. #.Example
  24. #  Install-Software -Targets "\\MyServer\MyShare\Targets\computers.txt" -Install "E:\Folder\install.exe"
  25. #
  26. #  Description
  27. #  -----------
  28. #  Copies install.exe from E:\Folder on the local computer to each of the target computers listed in computers.txt and
  29. #  initiates install.exe with no arguments.
  30.  
  31. [CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact='Low')]
  32. param(
  33.         [parameter(Mandatory = $true, Position = 0)]
  34.         [string]$Targets,
  35.         [parameter(Mandatory = $true, Position = 1)]
  36.         [string]$Install,
  37.         [parameter(Mandatory = $false, Position = 2)]
  38.         [string]$Arguments
  39. )
  40.  
  41. # Get target computer list
  42. $Computers = Get-Content $Targets
  43. $InstallString = "$Install $Arguments"
  44.  
  45. foreach ($Computer in $Computers) {
  46.         Copy-Item "$Install" \\$Computer\c$\TEMP
  47.        
  48.         Invoke-Command -ComputerName $Computer -ScriptBlock {
  49.                 Start-Process "$InstallString"}
  50. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me