Get-OfficeVersion

PowerShell function that gets the currently installed office version and returns either the year, the office folder, the registry location, or the number.

Updated 4/25/18 to support 64 bit office. Bitness is now a returnable Value Type.


Function Get-OfficeVersion {
#Allowing Cmdlet Bindings
[CmdletBinding(SupportsShouldProcess=$true)]
param(
  [Parameter(Position=0,Mandatory=$true)]
  [Alias("Value","VT")]
  [ValidateSet("Office Year", "Office Folder", "Registry Location","Registry Number","Bitness")]
  [string]$ValueTypeReturn,
    [Parameter(Position=1,Mandatory=$false)]
  [Alias("Computer","CN")]
  [string]$ComputerName = $env:COMPUTERNAME
)
Write-Verbose "Testing connection to $ComputerName"
if(Test-Connection -Quiet $ComputerName -Count 1){
Write-Verbose "Connection Successful to $ComputerName"
Write-Verbose "Detecting software for $ComputerName"
    if ((Test-path "\\$ComputerName\c$\Program Files (x86)\Microsoft Office\") -eq $true)
    {
        Write-Verbose "Found existing 32bit Office files on $ComputerName."
        if ((Test-path "\\$ComputerName\c$\Program Files (x86)\Microsoft Office\root\Office16\LIBRARY\") -eq $true)
        {
            Write-Verbose "Found 32bit Office 2016"
            $OfficeYear = "2016"           
            $ProgramFilesLocation = "C:\Program Files (x86)"
            $Bitness = "x32"
        }
        elseif ((Test-path "\\$ComputerName\c$\Program Files\Microsoft Office\root\Office16\LIBRARY\") -eq $true)
        {
            Write-Verbose "Found 64bit Office 2016"
            $ProgramFilesLocation = "C:\Program Files"
            $Bitness = "x64"
            $OfficeYear = "2016"   
        }
        if ((Test-path "\\$ComputerName\c$\Program Files (x86)\Microsoft Office\Office14\LIBRARY\") -eq $true)
        {
            Write-Verbose "Found 32bit Office 2010"
            $ProgramFilesLocation = "C:\Program Files (x86)"
            $OfficeYear = "2010"
            $Bitness = "x32"
        }
        elseif ((Test-path "\\$ComputerName\c$\Program Files\Microsoft Office\Office14\LIBRARY\") -eq $true)
        {
            Write-Verbose "Found 64bit Office 2010"
            $ProgramFilesLocation = "C:\Program Files"
            $OfficeYear = "2010"
            $Bitness = "x64"   
        }
        if ((Test-path "\\$ComputerName\c$\Program Files (x86)\Microsoft Office\Office15\LIBRARY\") -eq $true)
        {
            Write-Verbose "Found 32bit Office 2013"
            $OfficeYear = "2013"
            $ProgramFilesLocation = "C:\Program Files (x86)"
            $Bitness = "x32"
        }
        elseif ((Test-path "\\$ComputerName\c$\Program Files\Microsoft Office\Office15\LIBRARY\") -eq $true)
        {
            Write-Verbose "Found 64bit Office 2013"
            $OfficeYear = "2013"
            $ProgramFilesLocation = "C:\Program Files"
            $Bitness = "x64"   
        }
     
    }
elseif ((Test-path "\\$ComputerName\c$\Program Files\Microsoft Office\root\Office16\LIBRARY\") -eq $true)
        {
            Write-Verbose "No existing 32bit Office files on $ComputerName."
            Write-Verbose "Found 64bit Office 2016"
            $ProgramFilesLocation = "C:\Program Files"
            $Bitness = "x64"
            $OfficeYear = "2016"   
        }

switch ($OfficeYear)
        {
         "2016"
             {
        $OfficeFolder = "$ProgramFilesLocation\Microsoft Office\root\Office16"
        $RegistryLocation = "\Software\Microsoft\Office\16.0"
        $RegistryNumber = "16.0"
             }
         "2013"
            {       
            $OfficeFolder = "$ProgramFilesLocation\Microsoft Office\Office15"
            $RegistryLocation = "\Software\Microsoft\Office\15.0"
            $RegistryNumber = "15.0"
            } 
         "2010"
            {
            $OfficeFolder = "$ProgramFilesLocation\Microsoft Office\Office14"
            $RegistryLocation = "\Software\Microsoft\Office\14.0"
            $RegistryNumber = "14.0"
            }
        }

     


if ($ValueTypeReturn -eq "Office Year")
    {
    $VerboseString = $ComputerName + " has Office " + $OfficeYear
    Write-Verbose $VerboseString
    Write-Output $OfficeYear
    }
elseif ($ValueTypeReturn -eq "Office Folder")
    {
    $VerboseString = $ComputerName + " has Office installed in " + $OfficeFolder
    Write-Verbose $VerboseString
    Write-Output $OfficeFolder
    }
elseif ($ValueTypeReturn -eq "Registry Location")
    {
    $VerboseString = $RegistryLocation + " is the registry location for Office for " + $ComputerName
    Write-Verbose $VerboseString
    Write-Output $RegistryLocation
    }
elseif ($ValueTypeReturn -eq "Registry Number")
    {
    $VerboseString = $RegistryNumber + " is the registry number for Office for " + $ComputerName
    Write-Verbose $VerboseString
    Write-Output $RegistryNumber
    }
elseif ($ValueTypeReturn -eq "Bitness")
    {
    $VerboseString = $Bitness + " is the bitness for Office for " + $ComputerName
    Write-Verbose $VerboseString
    Write-Output $Bitness
    }
}
else
{
Write-Error "$ComputerName is not detected on the network, please check the connection and try again"
}
}

Comments

  1. The market for online slot video games is big, estimated at about $112 billion, and is set to grow by over 11% over the subsequent 5 years. At first glance, this determine may appear inflated, but want to|you must} think about simply how in style slots are amongst casino enthusiasts and even casual avid gamers. To illustrate, an estimated 53% of casino avid gamers in English-speaking countries enjoy slots, and this game type additionally occurs to have the 파라오 카지노 highest retention price. Aside from slots, Ducky Luck has broad range|a variety} of casino video games. We choose platforms that host as many game developers as attainable, providing a high payout share with a top-tier interface and the newest graphics. If web site|a net site} provides other casino video games, reside vendor video games, or sports activities betting, that is another plus.

    ReplyDelete

Post a Comment

Popular posts from this blog

Outlook VBA Macros for Journal Entries

SCCM PXE Boot Issues - No Advertisements Found

Updating Dell iDRAC ISM