Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with script 2

Status
Not open for further replies.

GrimR

IS-IT--Management
Jun 17, 2007
1,149
ZA

The app to match works, but the platform section does not seem to be working

$appToMatch = '*Mimecast*'

function Get-InstalledApps
{
if ([IntPtr]::Size -eq 4) {
$regpath = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
}
else {
$regpath = @(
'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
)
}
Get-ItemProperty $regpath | .{process{if($_.DisplayName -and $_.UninstallString) { $_ } }} | Select DisplayName, Publisher, InstallDate, DisplayVersion, UninstallString |Sort DisplayName
}

$result = Get-InstalledApps | where {$_.DisplayName -like $appToMatch}
If ($result -eq $null) {
Write-Host "'$appToMatch' NOT installed.";

#Check If x64 or x86
$platform = get-itemproperty HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration -name Platform


If($platform -eq "x86"){

#Office 2016 32-BIT STUFF
#Remove older version
$parameters = "/qn /x {948DCDCD-32BC-44A4-B970-B6E96D5E2CDC}"
$uninstallStatement = [System.Diagnostics.Process]::Start( "msiexec", $parameters )
$uninstallStatement.WaitForExit()

# Install Mimcast 32bit
Start-Process '\\server05\software$\Mimecast\Mimecast for Outlook 7.3.2061.19940 (32 bit)\Mimecast for Outlook 7.3.2061.19940 (32 bit).msi' -ArgumentList "/qn" -Wait
}

elseif($platform -eq "x64"){

#Office 2016 64-BIT STUFF
# Install Mimcast 64bit
Start-Process '\\server05\software$\Mimecast\Mimecast for Outlook 7.3.2061.19940 (64 bit)\Mimecast for Outlook 7.3.2061.19940 (64 bit).msi' -ArgumentList "/qn" -Wait
}
} else {
Write-Host "'$appToMatch' is installed."
exit
}

MCSE NT to 2012, MCITP:EA/SA, MCSA, MCDBA, MCTS, MCP+I, MCP
 
i think i fixed it
Code:
$appToMatch = '*Mimecast*'
$DisplayVersion ='7.3.2061.19940'

function Get-InstalledApps
{
    if ([IntPtr]::Size -eq 4) {
        $regpath = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
    }
    else {
        $regpath = @(
            'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
            'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
        )
    }
    Get-ItemProperty $regpath | .{process{if($_.DisplayName -and $_.UninstallString) { $_ } }} | Select DisplayName, Publisher, InstallDate, DisplayVersion, UninstallString |Sort DisplayName
}

$result = Get-InstalledApps | where {$_.DisplayName -like $appToMatch -and $_.DisplayVersion -eq $DisplayVersion }
If ($result -eq $null){
		Write-Host "'$appToMatch' NOT installed run installation.";

		 
		#Check If x64 or x86
		$platform = get-itemproperty HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration -name Platform
		If($platform -eq "x86"){

				#Office 2016 32-BIT STUFF
					#Remove older version
					Write-Host "'$appToMatch' is x86."
					$parameters = "/qn /x {948DCDCD-32BC-44A4-B970-B6E96D5E2CDC}"
					$uninstallStatement = [System.Diagnostics.Process]::Start( "msiexec", $parameters )
					$uninstallStatement.WaitForExit()

					# Install Mimcast 32bit
					Start-Process  '\\server05\software$\Mimecast\Mimecast for Outlook 7.3.2061.19940 (32 bit)\Mimecast for Outlook 7.3.2061.19940 (32 bit).msi' -ArgumentList "/qn" -Wait
				}else{
				($platform -eq "x64")
					Write-Host "'$appToMatch' is x64."
					#Office 2016 64-BIT STUFF
					# Install Mimcast 64bit
					Start-Process  '\\server05\software$\Mimecast\Mimecast for Outlook 7.3.2061.19940 (64 bit)\Mimecast for Outlook 7.3.2061.19940 (64 bit).msi' -ArgumentList "/qn" -Wait
			    }

} else {
		write-host "'$appToMatch'Found EXIT"
		exit
}

MCSE NT to 2012, MCITP:EA/SA, MCSA, MCDBA, MCTS, MCP+I, MCP
 
found an error this line
$platform = get-itemproperty HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration -name Platform
should be
$platform = (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration -name Platform).Platform

MCSE NT to 2012, MCITP:EA/SA, MCSA, MCDBA, MCTS, MCP+I, MCP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top