PoshCode Archive  Artifact [5a41514fe1]

Artifact 5a41514fe10a9158e99b93a601c8411d69a21323b1940aa320cdae356af5a6cd:

  • File NET-WMP-Install.ps1 — part of check-in [afa145b8df] at 2018-06-10 13:58:10 on branch trunk — Just a simple script to tie to a GPO to install .NET 4.5 and WMF 4.0 (user: Zerfam size: 2091)

# encoding: ascii
# api: powershell
# title: .NET/WMP Install
# description: Just a simple script to tie to a GPO to install .NET 4.5 and WMF 4.0
# version: 4.5
# type: function
# author: Zerfam
# license: CC0
# x-poshcode-id: 5622
# x-archived: 2014-12-13T19:03:37
# x-published: 2014-12-01T17:46:00
#
#
$DeploymentDir = '\\Server\Deployment\DotNET4.6_WMF4'

function message
{
	param 
	(
		[parameter(Mandatory=$true)]
		[string]$ErrorMessage
	)
	
	#Logfile
	$logFile = '\\Server\Logs\dotnet_deploy.log'
	
	#Build message
	$msg = "$env:ComputerName - "
	$msg += Get-Date -Format "yyyy-MM-dd h:mm tt - "
	$msg += $ErrorMessage
	
	#Log
	Add-Content $logFile "$StartTime - $msg "
	
	#Return value
	return $msg
}

#Check if .NET 4.5 is installed
$reg = Get-Item 'HKLM:\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\.NETFramework,Version=v4.5' -ErrorAction SilentlyContinue
if (-not $reg)
{
	#Install .NET 4.5
	
	message "Installing .NET 4.5."
	try
	{
		Start-Process -Wait -FilePath "$DeploymentDir\NDP451-KB2858728-x86-x64-AllOS-ENU.exe" -ArgumentList '/CEIPconsent /norestart /q'
	}
	catch [System.Exception]
	{
		message "Failed to run .NET installer: $_"
	}
}
else
{
	message ".NET 4.5 already installed."
}

#Check if PowerShell 4.0 is installed
if($PSVersionTable.PSVersion.Major -ne '4')
{
	#32 or 64 bit?
	$OS = (GWMI Win32_Processor).AddressWidth

	#Install WMF 4
	if($OS -eq "32")
	{
		message "Installing WMF4 32-bit."
		try
		{
			Start-Process -Wait -FilePath 'wusa.exe' -ArgumentList "$DeploymentDir\Windows6.1-KB2819745-x86-MultiPkg.msu /quiet /norestart"
		}
		catch [System.Exception]
		{
			message "Failed to run .NET installer: $_"
		}
	}
	elseif($OS -eq "64")
	{
		message "Installing WMF4 64-bit."
		try
		{
			Start-Process -Wait -FilePath 'wusa.exe' -ArgumentList "$DeploymentDir\Windows6.1-KB2819745-x64-MultiPkg.msu /quiet /norestart"
		}
		catch [System.Exception]
		{
			message "Failed to run .NET installer: $_"
		}
	}
}
else
{
	message "WMF4 already installed."
}