get-installedapplication issue

Topics: Archive - Deployment Scripts
Aug 14, 2014 at 3:12 AM
Basically trying to find out if .net 4.5 needs to be installed. If 4.5 or 4.5.1 isnt installed then install it.

I'm having difficulty with the below code. It always comes out that $dotnetcurrent is false. But while running the code it does show that $dotnet45 is finding the install on the machine. Any ideas why this isn't working? Am I doing something wrong with Get-InstalledApplication?

Thanks for any guidance.

$dotnet45 = Get-InstalledApplication -Name "Microsoft .NET Framework 4.5"
$dotnet451 = Get-InstalledApplication -Name "Microsoft .NET Framework 4.5.1"
$dotnetcurrent = $false

Show-InstallationProgress "Checking for .Net Framework 4.5"

if ( $dotnet45 -ne $null ) { $dotnetcurrent -eq $true }
if ( $dotnet451 -ne $null ) { $dotnetcurrent -eq $true }

if ( $dotnetcurrent -eq $false ) {
Write-Log "Installing .Net 4.5.1..."
Show-InstallationProgress "Installing .Net Framework 4.5.1..."
Execute-Process -FilePath "$dirFiles\NDP451-KB2858728-x86-x64-AllOS-ENU.exe" -Arguments "/q /norestart"
Write-Log "Finished .Net 4.5.1 Install."
}
Aug 15, 2014 at 8:14 PM
Edited Aug 15, 2014 at 8:15 PM
try this:

if ( $dotnet45 ) { $dotnetcurrent -eq $true }
if ( $dotnet451 ) { $dotnetcurrent -eq $true }

I think this will work too:

if ($dotnet45 -or $dotnet451 ) { $dotnetcurrent -eq $true }
Coordinator
Aug 20, 2014 at 3:27 PM
You can't use "-eq" to assign a value, it's only for checking a value, for assignment you should use :

$dotnetCurrent = $true

Get-InstallApplication will do a partial match so if you look for 4.5.1 it will also pick up installations of 4.5, so you need to parse the results like this:

$dotNet45 = $false
$dotNet451 = $false
Get-InstalledApplication -Name "Microsoft .NET Framework " | Select DisplayName | Foreach { If ($_.DisplayName -eq "Microsoft .NET Framework 4.5.1") { $dotNet451 = $true } ElseIf ($_.DisplayName -eq "Microsoft .NET Framework 4.5" {$dotNet45 = $true) } }