Run Powershell script until an application reaches a certain version

Rick Someone 411 Reputation points
2021-02-23T20:19:23.323+00:00

I have a PS job to upgrade Office but it doesn't go to the latest version unless I run it twice.
Some pc's are at 365, 1705, some are at 2002 and some are at 2008.
I wonder if there is a way to have PS run to get the latest version, 2008.

One suggestion I found said to use, as a variable argument:
/update user displaylevel=true updatetoversion=16.0.etc

The first time I run it on a 1705 pc, it upgrades to 2002, then I have to run it again to get to 2008. If it's not a huge script with crazy requirements and ifs/thens, I would be interested if someone had a working PS that runs to get the latest of something, or runs until it gets to that version.

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

33 answers

Sort by: Most helpful
  1. js2010 191 Reputation points
    2021-03-05T15:20:57.59+00:00
    if ( (get-package 'Microsoft Office Professional Plus*' -provider programs | % version) -lt '16.0.4266.1001' ) { 
      'install stuff' }
    

    Was this answer helpful?

    1 person found this answer helpful.

  2. Rick Someone 411 Reputation points
    2021-02-25T18:14:13.047+00:00

    I have figured out the syntax for all of this, but when it runs, it completely locks the pc. I can't move the cursor or pretty much do anything. So getting into the Task Mgr to check is out. There still must be something wrong with my script.....this it is complete:
    I think perhaps some lines further down are out of order?

    cd HKLM:\

    New-Item -Path HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\ -Name Office -force

    New-Item -Path HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Office\ -Name 16.0 -force

    New-Item -Path HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Office\16.0 -Name common -force

    New-Item -Path HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Office\16.0\common -Name OfficeUpdate -force

    New-Item -Path HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Office\16.0\common\OfficeUpdate

    New-ItemProperty -Path HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Office\16.0\common\OfficeUpdate -Name EnableAutomaticUpdates -Value 1 -Force

    New-Item -Path HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Office\ -Name ClickToRun -force

    New-Item -Path HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Office\ClickToRun\ -Name Configuration -force

    New-ItemProperty -Path HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Office\ClickToRun\Configuration -Name UpdatesEnabled -Value "True"

    $updatetoversion="16.0.13127.21210"

    $UpdateArguements = "/update user displaylevel=true"

    $version=Get-WmiObject win32_product | where{$_.Name -like "Microsoft Office 365*"} | Select-Object -ExpandProperty Version

    while($version -ne $updatetoversion){

    Start-Process "C:\Program Files\Common Files\microsoft shared\ClickToRun\OfficeC2RClient.exe" $UpdateArguements

    }

    Was this answer helpful?

    0 comments No comments

  3. Rick Someone 411 Reputation points
    2021-02-25T16:02:21.73+00:00

    I guess my main question is that I tried to incorporate your conditional variables into the PS I have:

    What happens is I get a dos box that appears to be running something but the office update never occurs.

    New-ItemProperty -Path HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Office\ClickToRun\Configuration -Name UpdatesEnabled -Value "True"
    $updatetoversion="16.0.13127.21210"
    $version=Get-WmiObject win32_product | where{$_.Name -like "Microsoft Office 365*"} | Select-Object -ExpandProperty Version
    while($version -ne $updatetoversion){

    upgrade Office

    }
    $UpdateEXE ="C:\Program Files\Common Files\microsoft shared\ClickToRun\OfficeC2RClient.exe"
    $UpdateArguements = "/update user displaylevel=true"
    Start-Process $version $UpdateEXE $UpdateArguements

    Was this answer helpful?

    0 comments No comments

  4. Rick Someone 411 Reputation points
    2021-02-25T14:23:46.077+00:00

    My question is.....
    How do I add your version detection portion to my existing PS?
    I really dont need the $UpdateArguements line if I use your entries, correct?

    Was this answer helpful?

    0 comments No comments

  5. Anonymous
    2021-02-24T08:06:38.05+00:00

    Hi,

    You can detect the current office version using the WMI class Win32_Product.

    $updatetoversion="16.0.etc"  
    $version = Get-WmiObject win32_product  | where{$_.Name -like "Microsoft Office Professional Plus*"} | Select-Object -ExpandProperty Version  
    while($version -ne $updatetoversion){  
    #upgrade the office  
    }  
    

    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.

    Was this answer helpful?


Your answer

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