Monday, September 22, 2014

Enable .Net Framework 3.5 SP1 in Windows 8.1

I thought I would right up how I enable .Net Framework 3.5 SP1 in Windows 8.1 using SCCM and PowerShell. Both as an application that can be pushed to machines, and during OS deployments in the task sequence.
First create a powershell script with the command:
# Enable .Net 3.5 Framework SP1 on Windows 8.1 Machines.
# Must have SXS folder from Windows 8.1 ISO in directory with script
#Enable .Net 3.5
enable-windowsoptionalfeature -featurename NetFx3 -Online -NoRestart -LimitAccess -All -Source .\SXS -LogLevel WarningsInfo -ErrorAction Continue
I call my script “EnableNet35.ps1”.
Next you will need the folder “sxs” from your Windows 8.1 ISO disk. This folder is located in the sources folder. My ISO is on a network share so the path may be different from yours.

Copy this folder and your script to your SCCM Source folder.

Create your Application and Deployment Type like so:

We will use a Custom PowerShell script as the detection method.

If ((Get-windowsoptionalfeature -FeatureName NetFx3 -Online | Select-Object -ExpandProperty State) -ne "Enabled")
        # .NET Framework 3.5SP1 is not enabled on this system
            # Its installed so populate 'stdout', write-host will do this
            Write-host ".NET Framework 3.5 SP1 is already installed"

If you wish to use this in an OSD Task Sequence, or any PowerShell commands, you may have to enable PowerShell during the Task Sequence.

How to Enable PowerShell during an OSD Task Sequence.

You will have to input settings into the registry of the computer to allow it to run PowerShell unrestricted. I use the following script (thanks Nash Pherson and JDA for the script):
REM JDA 2/25/14

IF EXIST %SystemRoot%\Sysnative\cmd.exe ("%SystemRoot%\Sysnative\cmd.exe" /C "%~dpnx0") & (GOTO end)

reg add HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell /t REG_DWORD /v EnableScripts /d 1 /f
reg add HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell /v ExecutionPolicy /d Unrestricted /f
reg add HKLM\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell /t REG_DWORD /v EnableScripts /d 1 /f
reg add HKLM\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell /v ExecutionPolicy /d Unrestricted /f

Name this script “enable_ps.cmd” and create a SCCM package called Enable PowerShell with “enable_ps.cmd” as the Command Line.

Run this package early in your OSD Task Sequence before your first PowerShell script executes.