Unattended deployment

Andrews Dumith 41 Reputation points
2021-12-20T14:17:51.417+00:00

With the help of several collaborators, I could put together a process that automates -in unattended mode- the updating of a group of solutions.

I leave the script to serve for others.

If there is anything to improve, let me know to include it.

Have a nice day and happy holidays.

P.D. :
1.- ONLY run for 32bits
2.- Must to be run as admisnistrator
3.- ONLY run for localhost

########## Setup Variables for Script ##########
#ProcessName:  Apps to close 
#AppstoRemove: Apps to uninstall
#WorkingDir:   Working directory
#Computers:    Workstations targets
#Transcript:   Progress report
$ProcessName = @(
'OUTLOOK.EXE'
'WINWORD.EXE'
'ACROBAT.EXE'
)
$AppstoRemove =  @(
'iManage Share Plug-in for iManage Work (x86)'
'iManage Work FileSite (x86)'
'Workshare Professional'
'Drafting Assistant'
'Westlaw Solutions'
'Microsoft Office Professional Plus 2016'
)
$WorkingDir = "\\tkdata\apps\IManage (DMS)\Work 10\"
#$Computers = Get-Content "\\tkdata\apps\IManage (DMS)\Work 10\InstallList.txt"
$Computers = @('localhost')
$Transcript = "\\tkdata\apps\IManage (DMS)\Work 10\transcript.txt"

########## Start Logging ##########
Start-Transcript -path $Transcript -Append 

########## Clossing Apps ##########
Write-Host "Closing Apps"
ForEach ($Process in $ProcessName) 
{
   $ReturnVal = taskkill /im $Process /t /f
   if ($ReturnVal) {
       Write-Host "Process: $Process terminated successfully"
   }
}

########## Removing Apps ##########
Write-Host "Removing Apps"
foreach ($App in $AppstoRemove) 
 {
    $RegApp = Get-Itemproperty 'HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' |
        Select-Object DisplayName, DisplayVersion, UninstallString, PSChildName |
        Where-Object { $_.DisplayName -match "^*$App*"}
    if($RegApp) {
        if($RegApp.Uninstallstring -match '^msiexec')
        {
             $UninstallString = "$($RegApp.UninstallString -replace '/I', '/X' ) /qn /passive /norestart"
        } else {
             $UninstallString = $RegApp.UninstallString
        }
        $RegApp.UninstallString
        $pos = $UninstallString.tolower().IndexOf('.exe')
        $exe =  $UninstallString.Substring(0,$pos + 4)
        $args = $UninstallString.Substring($pos + 4).trim()
        $exe,$args = ($RegApp.UninstallString).split(' ')
        $args -replace '/I','/X'
        Start-Process $Exe -ArgumentList "$args" -NoNewWindow -Wait
    } else {
        "We did not find $App"
    }
}

########## Install Apps ##########
try 
  {
   #### Starting installation ####
   Write-Host "Starting installation"
   New-Item -ItemType directory -Path "\\$Computers\c$\temp\Office2019"
   Copy-Item "\\tkdata\apps\Microsoft\Office Pro Plus 2019 x86-x64\*" "\\$Computers\c$\temp\Office2019" -Recurse
   Write-Host "Installing: Office Pro Plus 2019"
   $ReturnVal=Invoke-Command -ScriptBlock {Start-Process -WorkingDirectory "c:\temp\Office2019\" -FilePath "c:\temp\Office2019\Install-32.bat" -Wait -Verb RunAs}
   Write-Host $ReturnVal

   Write-Host "Installing: West Law Drafting Assistant"
   New-Item -ItemType directory -Path "\\$Computers\c$\temp\WLDA"
   Copy-Item "\\tkdata\apps\ThomsonReuters (West Law Drafting Assistant)\*" "\\$Computers\c$\temp\WLDA" -Recurse
   $ReturnVal=Invoke-Command -ScriptBlock {Start-Process -WorkingDirectory "c:\temp\WLDA\" -FilePath "c:\temp\WLDA\trdt.exe" -ArgumentList "/passive" -Wait -Verb RunAs}
   Write-Host $ReturnVal

   Write-Host "Installing: Windows Webview 2 Runtine"
   New-Item -ItemType directory -Path "\\$Computers\c$\temp\WWV2"
   Copy-Item "\\tkdata\apps\Microsoft\MicrosoftEdgeWebView2RuntimeInstallerX86.exe" "\\$Computers\c$\temp\WWV2" -Recurse
   $ReturnVal=Invoke-Command -ScriptBlock {Start-Process -WorkingDirectory "c:\temp\WWV2\" -FilePath "c:\temp\WWV2\MicrosoftEdgeWebView2RuntimeInstallerX86.exe" -ArgumentList "/silent /install" -Wait -Verb RunAs}
   Write-Host $ReturnVal

   Write-Host "Installing: I-Manage 10"
   New-Item -ItemType directory -Path "\\$Computers\c$\temp\IManage10"
   Copy-Item "\\tkdata\apps\IManage (DMS)\Work 10\iManage Work Desktop for Windows 10.6.0.66 (x86 Office)\*" "\\$Computers\c$\temp\IManage10" -Recurse   
   $ReturnVal=Invoke-Command -ScriptBlock {Start-Process -WorkingDirectory "c:\temp\IManage10\" -FilePath "c:\temp\IManage10\InstalliManage-32.bat" -Wait -Verb RunAs}
   Write-Host $ReturnVal

   Write-Host "Installing: WorkShare Professional"
   New-Item -ItemType directory -Path "\\$Computers\c$\temp\WSP"
   Copy-Item "\\tkdata\apps\Workshare\Workshare Professional 10.11.21502.0 Full Install (32-bit)\*" "\\$Computers\c$\temp\WSP" -Recurse
   $ReturnVal=Invoke-Command -ScriptBlock {Start-Process -WorkingDirectory "c:\temp\WSP\" -FilePath "c:\temp\WSP\InstallWSP-32.bat" -ArgumentList "/qn /norestart" -Wait -Verb RunAs}
   Write-Host $ReturnVal
   }
catch [System.Exception]
   {
     Write-Output $_ 
     return '$ReturnValue'
    }

Stop-Transcript

########## Wait 2 Minutes ##########
Start-Sleep -Seconds 120

########## Get Installed Software ##########

Write-Host "Checking for Installed Software"

$Result32 = Invoke-Command -ScriptBlock {Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* -Exclude RunspaceId,PSShowComputerName } | 
Select-Object PSComputerName, DisplayName, Publisher, InstallDate | Sort-Object DisplayName

$Result64 = Invoke-Command -ScriptBlock {Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* -Exclude RunspaceId,PSShowComputerName } | 
Select-Object PSComputerName, DisplayName, Publisher, InstallDate | SSort-Object DisplayName

$Result1 = $Result64 + $Result32
$Result2 = $Result1 | Where-Object {$_.DisplayName -like 'Microsoft Office Professional Plus 2019' -or $_.DisplayName -like 'TR Drafting Tools*' -or $_.DisplayName -like 'Microsoft Edge WebView*' -or $_.DisplayName -like 'iManage*' -or $_.DisplayName -like 'WorkShare*'}
$FinalResults = $Result2 |  Export-Csv "$WorkingDir\FinalResults.csv" -NoTypeInformation -Append

########## Remove temporary files and folder on each PC ##########
Write-Host "Removing Temporary files"
$RemovalPath = "\\$Computers\c$\temp\"
Get-ChildItem  -Path $RemovalPath -Recurse  | Remove-Item -Force -Recurse
Remove-Item $RemovalPath -Force -Recurse

Write-Host "Process Completed"
Write-Host "Restaring WorkStation"
Restart-Computer
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.