Advertisement
Dennisaa

Execute artefacts remotely

Mar 9th, 2014
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2. .Synopsis
  3.    Install Windows artefacts upon which our applications are dependent
  4. .Description
  5.    Ensure that all drive references are to C, never to D etc.
  6. .Example
  7.  Install-WindowsArtefacts -RemoteComputerName "dennis-pc" -BinariesLocation \sandbox\PowerShell\artefacts -LocalTest
  8. #>
  9. function Install-WindowsArtefacts
  10. {
  11.     Param (
  12.         [Parameter(Mandatory=$true, Position=0)]
  13.         [string[]]
  14.         $RemoteComputerName,
  15.         [Parameter(Mandatory=$true, Position=1)]
  16.         [string]
  17.         $BinariesLocation,
  18.         [Parameter(Mandatory=$false, Position=2)]
  19.         [switch]
  20.         $LocalTest
  21.     )
  22.     Begin {
  23.         $localComputer = $env:COMPUTERNAME
  24.     }
  25.     Process {
  26.         $VCR32 = "vcredist_x86.exe"
  27.         $VCR64 = "vcredist_x64.exe"
  28.         $CRR = "CRRuntime_12_0_mlb.msi"
  29.         $DOTNET451 = "NDP451-KB2858728-x86-x64-AllOS-ENU.exe"
  30.  
  31.         $subFolder = ""
  32.         if ($LocalTest) {
  33.             $subFolder = 'subFolder'
  34.         }
  35.  
  36.         foreach ($computer in $RemoteComputerName) {
  37.             if (!(Test-Path -Path "\\$computer\C$\$BinariesLocation\$subFolder")) {
  38.                 New-Item -ItemType Directory "\\$computer\C$\$BinariesLocation\$subFolder"
  39.  
  40.             }
  41.             Copy-Item -Path \\$localComputer\C$\$BinariesLocation\$VCR32 -Destination \\$computer\C$\$BinariesLocation\$subFolder\$VCR32 -Force
  42.             Copy-Item -Path \\$localComputer\C$\$BinariesLocation\$VCR64 -Destination \\$computer\C$\$BinariesLocation\$subFolder\$VCR64 -Force
  43.             Copy-Item -Path \\$localComputer\C$\$BinariesLocation\$CRR -Destination \\$computer\C$\$BinariesLocation\$subFolder\$CRR -Force
  44.             Copy-Item -Path \\$localComputer\C$\$BinariesLocation\$DOTNET451 -Destination \\$computer\C$\$BinariesLocation\$subFolder\$DOTNET451 -Force
  45.  
  46.             $session = New-PSSession -ComputerName $computer
  47.             Invoke-Command -Session $session -ScriptBlock {
  48.                 param($BinariesLocation1, $subFolder1, $VCR321, $VCR641, $CRR1,$DOTNET4511 )
  49.                 Start-Process -FilePath "C:\$BinariesLocation1\$subFolder1\$VCR321" -ArgumentList "/q /norestart" -wait
  50.                 Start-Process -FilePath "C:\$BinariesLocation1\$subFolder1\$VCR641" -ArgumentList "/q /norestart" -wait
  51.                 Start-Process -FilePath "C:\$BinariesLocation1\$subFolder1\$CRR1" -ArgumentList "/q /norestart" -wait
  52.                 Start-Process -FilePath "C:\$BinariesLocation1\$subFolder1\$DOTNET4511" -ArgumentList "/q /norestart" -wait
  53.             } -ArgumentList ($BinariesLocation, $subFolder, $VCR32, $VCR64, $CRR,$DOTNET451)
  54.             Remove-PSSession $session
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement