Skip to content

Instantly share code, notes, and snippets.

@xenoid
Last active April 6, 2018 20:43
Show Gist options
  • Save xenoid/c12333da0ac62b05b0f4d81500672f7d to your computer and use it in GitHub Desktop.
Save xenoid/c12333da0ac62b05b0f4d81500672f7d to your computer and use it in GitHub Desktop.
##########################################################################################
# Simple script for installing Microsoft .NET Framework because of some ancient software #
# refer to https://gist.github.com/computerality/48666348cbf8980a3204f1e3ae84c55e #
# Please insert your own URLs to .NET Framework #
##########################################################################################
$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("Select your software to be installed",0,"Hi",0x1)
Function Get-FileName($initialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
}
$Software = Get-FileName
#Create working-directory if it does not already exist (Should be empty to avoid data loss)
$workingdirectory = 'C:\temp\netfxinstall'
md -Force $workingdirectory
#1. Download .net framework from microsoft.com.
$wshell.Popup("Downloading .net framework",0,"Download ...",0x1)
$downloader = new-object System.Net.WebClient
$downloader.DownloadFile('### URL TO YOUR NET FRAMEWORK X64 EXE ###',"$workingdirectory\NetFx20SP2_x64.exe")
#2. Realize it is x64 and not x86 as needed.
$wshell.Popup("Oh wait, I downloaded x64?",0,"Really?",0x1)
#3. Download .net framework 2.0 sp2 from microsoft.com
$wshell.Popup("Downloading .net framework 2.0 sp2",0,"Download ...",0x1)
$downloader = new-object System.Net.WebClient
$downloader.DownloadFile('### URL TO YOUR NET FRAMEWORK X86 EXE ###',"$workingdirectory\NetFx20SP2_x86.exe")
#4. Realize it is only the service pack and does not include the installer.
$wshell.Popup("Realize it is only the service pack and does not include the installer.",0,"...",0x1)
#5. Find a USB cd rom drive.
#6. Copy the exe off of the cd.
$wshell.Popup("Find a USB cd rom drive. Copy the exe off of the cd.",0,"...",0x1)
$wshell.Popup("Specify path to .NET Framework exe",0,"...",0x1)
$NetFxEXE = Get-FileName
Copy-Item -Path "$NetFxEXE" -Destination "$workingdirectory\NetFx2.exe"
& "$workingdirectory\NetFx2.exe"
#7. Get windows installer error about not being able to install .net framework 3.5(which includes 2.0 and 3.0).
$wshell.Popup("Oh well, this did not work ...",0,"ERROR",0x1)
#8. Get Windows Server 2016 installation iso and extract \sources\sxs
$wshell.Popup("Please select a Windows Server 2016 ISO",0,"Select ISO ...",0x1)
$WinSrv2016ISO = Get-FileName
$mountResult = Mount-DiskImage -ImagePath "${WinSrv2016ISO}" -PassThru
$driveLetter = ($mountResult | Get-Volume).DriveLetter
#9. Run the following command from googling: dism /online /enable-feature /featurename:NetFx3 /Source:D:\sources\sxs
$wshell.Popup("Run the following command from googling: dism /online /enable-feature /featurename:NetFx3 /Source:D:\sources\sxs",0,"DISM",0x1)
& dism /online /enable-feature /featurename:NetFx3 /Source:${driveLetter}:\sources\sxs
#10. Get error about missing a dependency.
$wshell.Popup("You are missing some dependency",0,"ERROR",0x1)
#11. Run the following command: dism /online /enable-feature /featurename:NetFx3ServerFeatures /Source:D:\sources\sxs
$wshell.Popup("Run the following command: dism /online /enable-feature /featurename:NetFx3ServerFeatures /Source:D:\sources\sxs",0,"DISM",0x1)
& dism /online /enable-feature /featurename:NetFx3ServerFeatures /Source:D:\sources\sxs
#12. Run this command again: dism /online /enable-feature /featurename:NetFx3 /Source:D:\sources\sxs
$wshell.Popup("Run this command again: dism /online /enable-feature /featurename:NetFx3 /Source:${driveLetter}:\sources\sxs",0,"DISM",0x1)
& dism /online /enable-feature /featurename:NetFx3 /Source:${driveLetter}:\sources\sxs
#Cleanup
Remove-Item $workingdirectory\NetFx2.exe
Remove-Item $workingdirectory\NetFx20SP2_x64.exe
Remove-Item $workingdirectory\NetFx20SP2_x86.exe
Dismount-DiskImage -ImagePath ${WinSrv2016ISO}
#13. Install the software.
$wshell.Popup("Install the software.",0,"Finally ...",0x1)
& $Software
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment