Still having PS issues with upgrading software based on version

Rick Someone 411 Reputation points
2021-03-17T17:34:04.037+00:00

I just don't know the syntax to make this end. It does its job; it takes Office from 1705 to 2008 by version #, but once it does, it continues an endless loop of "Checking for Updates."
Also, after the first run through, a popup comes up saying Office has been Upgraded.
It requires clicking OK for the 2nd run through to begin. I'm wondering how to avoid that as well if possible.

$UpdateEXE ="C:\Program Files\Common Files\microsoft shared\ClickToRun\OfficeC2RClient.exe"
2. $UpdateArguements = "/update user displaylevel=true"
3. $updatetoversion="16.0.etc"
4. $version = Get-WmiObject win32_product | where{$_.Name -like "Microsoft Office Professional Plus*"} | Select-Object -ExpandProperty Version
5. while($version -ne $updatetoversion){
6. Start-Process $UpdateEXE $UpdateArguements -Wait
7. }

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,355 questions
0 comments No comments
{count} votes

9 answers

Sort by: Most helpful
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 29,486 Reputation points Microsoft Vendor
    2021-03-22T04:05:42.353+00:00

    Hi,

    The version of Office 365 cannot be retrieved from the WMI class win32_product and it appears OfficeC2RClient.exe calls OfficeClickToRun.exe to update Office 365. If you want to update to a specified version you have to add the "updatetoversion" parameter to OfficeC2RClient. Please check to see if this works for you.

    $UpdateEXE ="C:\Program Files\Common Files\microsoft shared\ClickToRun\OfficeC2RClient.exe"  
    $updatetoversion = "16.0.13127.21348"  
    $UpdateArguements = "/update user displaylevel=true updatetoversion=$updatetoversion"  
    $path = "HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration"  
    $name = "VersionToReport"  
    $version = Get-ItemProperty -Path $path | Select-Object -ExpandProperty $name  
    $ClickToRunSvc = Get-WmiObject win32_service | Where-Object { $_.name -eq 'ClickToRunSvc'}  
    while($version -ne $updatetoversion){  
        if($ClickToRunSvc.State -eq 'Stopped'){  
            Start-Service -Name 'ClickToRunSvc'   
            Start-Process $UpdateEXE $UpdateArguements -Wait  
            $ClickToRunSvc = Get-WmiObject win32_service | Where-Object { $_.name -eq 'ClickToRunSvc'}  
        }  
        else{  
            $OfficeClickToRun = Get-Process -Name OfficeClickToRun  
            if($OfficeClickToRun.count -eq 1){  
                Start-Process $UpdateEXE $UpdateArguements -Wait  
            }  
            else{  
                Start-Sleep -Seconds 10  
            }  
        }  
        $version = Get-ItemProperty -Path $path | Select-Object -ExpandProperty $name  
    }  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

  2. Rich Matheisen 44,696 Reputation points
    2021-03-17T19:29:26.85+00:00

    Try changing your $UpdateArguement string to use "displaylevel=false" . . . and maybe add "forceappshutdown=true". But do be advised that the OfficeC2RClient software is "deprecated". I have no idea what might replace it.

    The last time we went through this you threw up your hands in despair. If you want to try again, see below:

    $UpdateEXE = "C:\Program Files\Common Files\microsoft shared\ClickToRun\OfficeC2RClient.exe"
    $UpdateArguements = "/update user displaylevel=true"
    [version]$updatetoversion = "16.0.etc"
    [version]$Script:version = Get-WmiObject win32_product | where { $_.Name -like "Microsoft Office Professional Plus*" } | Select-Object -ExpandProperty Version
    while ($Script:version -lt $updatetoversion) {      # if new version is greater than or equal to the desired version don't do anything
        [version]$previousversion = $Script:version     # remember the version this loop started with
        Start-Process $UpdateEXE $UpdateArguements -Wait
        $Script:version = Get-WmiObject win32_product | where { $_.Name -like "Microsoft Office Professional Plus*" } | Select-Object -ExpandProperty Version
        if ($Script:version -eq $previousversion){      # if start-process ran and version didn't change after update
                    break                               # get out of the loop or risk staying in an infinite loop
                                                        # or waiting for new software updates to be loaded
        }
    }
    if ($Script:version -lt $updatetoversion){
        Write-Host "Update ran but failed to install the required version. " $updatetoversion ">" $Script:version
    }
    else{
        Write-Host "Update successful: " $updatetoversion "<=" $Script:version
    }
    
    0 comments No comments

  3. Rick Someone 411 Reputation points
    2021-03-17T23:07:41.01+00:00

    Thanks. I really was fed up with the whole thing. I had so many approaches and none took. I finally got it to run twice, up to my version, but then it just kept checking for updates in a loop.
    I really do wish I knew more about PS. I do well getting us past things that our gpo group hasn't gotten around to, through MDT.
    By the way, I'll have to change the condition to Microsoft Office because the old version is MS Office pro plus and the new version is named MS Office365.
    So about that pop up saying your updates are done, half way through and I have to click ok for it to continue on, can that be added in any way?

    0 comments No comments

  4. Rick Someone 411 Reputation points
    2021-03-18T14:07:33.6+00:00

    I have a few questions about the script:

    5 says that while the current version is lt the desired version (which is true) do nothing.

    However it does run once. From 1705 to 1902 (not 2008 yet).

    Once it runs once, an Office box pops up saying updates were applied, but the DOS box says updates failed (#14).

    In line 14, if the pc version is -lt the desired version, do I not want the script to continue until it does -eq or -ge the updateToVersion?

    I guess my main question is how does this continue to run until the versions =?

    If version -eq previousversion, break, because they match. Got it.

    IF the old is less than the desired, it says I just get a message that they failed.

    Otherwise, write that updates occurred.

    But If script:version -lt updatetoversion, we want it to run until it does equal, correct?

    I'm just trying to sort it out in my head. Because when I run the script right away the DOS comes up with Updates ran but failed to install, while the MS box says updates were finished (to 1902).
    If I run it a 2nd time, the DOS comes up immediately saying it failed but yet downloaded are running and applying, this time to the correct version.


  5. Rick Someone 411 Reputation points
    2021-03-18T17:47:50.36+00:00

    Well, it only does run once. The Office popup (which Id love to bypass) says Office updates were done, while the DOS box says it failed.
    I just cannot get it to ever run more than once, to the $updatetoversion...ever since I started this process. I think that popup box telling me that Updates were completed might be breaking or pausing the continuation.
    Think some sort of -SILENT or /silent /quiet or such may stop that?