question

RickSomeone-1151 avatar image
0 Votes"
RickSomeone-1151 asked IanXue-MSFT commented

Still having PS issues with upgrading software based on version

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

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
 }
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RickSomeone-1151 avatar image
0 Votes"
RickSomeone-1151 answered

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?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RickSomeone-1151 avatar image
0 Votes"
RickSomeone-1151 answered RickSomeone-1151 edited

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.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Line #5 is only testing the value you supplied ($updatetoversion) against the version returned from your WMI query ($version). If they're the same there isn't anything to do.

If the click-to-run (which is a deprecated program) updates the software from 1705 to 1902 that's a "good thing". But that's still less than the desired version, so click-to-run runs again -- but if there's not further updates available it really can't do anything, so the WMI query returns the same version number that existed when the "while" loop began. At that point it leaves the "while". If you ignore that check and there are no further updates (according to click-to-run) then the loop will repeat, over and over and over until either click-to-run discovers an update that moves the version number to either equal or exceed your desired version (at which point the loop would end).

0 Votes 0 ·

Why you get different feedback from the execution of click-to-run (again, a deprecated bit of software) I can't say. But if the click-to-run process is returning something you can capture that output if you assign the result of Start-Process to a variable. Search for "start-process get output" for several different approaches.

0 Votes 0 ·
RickSomeone-1151 avatar image
0 Votes"
RickSomeone-1151 answered RichMatheisen-8856 commented

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?

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Here's what I say yesterday about that click-to-run app:

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.


Why not run your script in an IDE in "debug" mode and place a breakpoint right before the "while"? Examine the two variables ($version and $updatetoversion) to verify that they're what you expect, and then single-step into the "while", checking the values (including $previousversion) for each step. Are they what you expect? Does $version change after running click-to-run and Get-WMIObject?

Without knowing what values the script is dealing with you'll only be guessing.

0 Votes 0 ·
RickSomeone-1151 avatar image
0 Votes"
RickSomeone-1151 answered

Sounds like a plan. I know it works because the Office popup tells me Updates were installed and I can verify the version of Word, Excel, etc.
But almost immediately after kicking off the PS, the DOS displays line 15 and waits for me to press a key to close it. Strange.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RickSomeone-1151 avatar image
0 Votes"
RickSomeone-1151 answered RichMatheisen-8856 commented

I'll test this in the morning. What I'm missing in my logic is

If the initial version is less than the uptoversion, start the exe

Then, check the version again.

If the version checked equals the previous version (which is already is in line 6)
then quit (without updating).

If the version checked is less than the updateto, quit and say no updates installed.

So I guess I'm missing where, if the script:version is less than updateto (line 14), there's no updating. Like 9 also says is the script:version -eq previous version, quit.
So where is it that says, if the script:version -ne updateto, run, then run again until it does get there? It seems that both IF's answer what happens when they don't match.

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The while encompasses lines 5 through 13 and it will continue to run as long as:

  1. The $version variable contains a value that is less than the variable $updateto version (that's the condition that causes the code in the While loop to execute)
    AND

  2. After retrieving the version of the software AFTER running an update the $previousversion and the updated $version are the NOT same value

OTOH, if after running the update, the Get-WMIObject sets the $version variable to that is the same value as the $previousversion variable, a "break" is done, thereby leaving the While loop (lines 9 through 12.

Lines 14 through 19 are OUTSIDE the while loop. They're there just to illustrate under what conditions the While loop ended. They have nothing to do with the updating of the software.


0 Votes 0 ·

I understand that as is detailed. Thanks. My last question is, the current version is compared to the uptoversion. WHILE the current version is LT the updateto, the start-process runs.
Then I see two IFs, one is the current version = the previous (nothing happens) and
IF version is LT the updateto, break (nothing happens).
I get that.
What I don't get is what should happen when the condition IS met that the current version and the updateto are equal. That should happen, because if I run this twice, it takes me to the updateto, but gets into a loop. So once the versions match (old and upto) it should stop and say Update Successful. BTW, the moment I kick off the PS, the DOS box says Unable to install.... while the updates are actually downloading. I think I just need a small bit of adjustment to get it where it needs to be. I don't know how to run this in debug mode with breaks so I just run it each time.

0 Votes 0 ·

When $Script.version and $updatetoversion are equal the While loop will exit (because the test on line #5 will fail). At that point the $Script:version variable will hold the version of the last software update.

There is only one "if" statement within the while loop (on line #9). That's the one that will leave the while loop if the version number did not change after running the update.

The conditional statement on line #5 will exit the loop if the current $Script:version is greater than, or equal to, the $updatetoversion. The conditional statement on line #9 will exit the loop if updating the software didn't change the version (i.e. the current $Script:version is the same as it was before the update ran).

What you may be experiencing is that the "click-to-run" program isn't actually doing an update, but just kicking off another task that downloads and installs the software. You could try inserting a Start-Sleep after the update.

0 Votes 0 ·
RickSomeone-1151 avatar image
0 Votes"
RickSomeone-1151 answered RickSomeone-1151 edited

So what I see from running the script, the version is what's current. Then there's the updateto.

While runs if version is less than updateto.



Then it checks the version again.

If version = previous version (which I don't see why it would), then it breaks the loop of running/checking. So that stops the PS.

If version is less than updateto, the script stops.



Why would the script run once, compare the version to the updateto, and stop on either IF? I still don't see where the Start-Process runs until the IF means version=updateto.
Why would the scriptversion ever be less than the updateto, except while the loop is running to get it there, which I think is only two runs)?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

IanXue-MSFT avatar image
1 Vote"
IanXue-MSFT answered IanXue-MSFT commented

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.

· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I'll give this a go. I get that if the version don't equal, where nothing has changed, it should keep running rather than stop. Previously, the script was having me see that if the previousversion is less than the updateto, it would stop as well.

Running it twice got me from (1705 to 1902), then 1902 to 2008. But then it would constantly keep 'checking for updates.'

Also, is there any way, between the start-process steps, to prevent that Office popup "Your Office has been upgraded?" It won't continue on until you click OK.

0 Votes 0 ·

Where is the Accept Answer button? I'm truly not a fan of this new forum vs the TechNet one.

0 Votes 0 ·

The button should be at the bottom of the answer.

0 Votes 0 ·

Where could I add a comment that the Office upgrade completed successfully at the very end? I'm not sure which line determines that the old and updateto versions match and then exits the PS. I could add a white-host message right after the condition is met.

0 Votes 0 ·

You can append Write-Host "The Office upgrade completed successfully" at the end of the script.

0 Votes 0 ·

This actually works. It runs once rather than stopping at each version along the way.

When it's fully done, the version is at the highest version I'm asked to move up to.

I may add a text at the end stating that the upgrade has been completed successfully.
Thanks so much for this version of the PS. It doesn't even bring up a popup stating that Office has been upgraded. That's great.

0 Votes 0 ·
RickSomeone-1151 avatar image
0 Votes"
RickSomeone-1151 answered IanXue-MSFT commented

IAN-XEU, I ran the script several times with no issue, but today I was prompted with that box,
"There are updates available. Click OK to start upgrade."

Is there a way to bypass that? The automation breaks until someone answers YES.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Try setting "displaylevel=false" in $UpdateArguements.

0 Votes 0 ·