This is the next part in an ongoing series about Powershell. You may have heard about how awesome Powershell is but have struggled to find ways to make it useful in your day to day work. That's what this series is going to address. It'll provide scripts and knowledge to address practical everyday problems!
This is a script you can run that'll upgrade you to the newest version of the Windows Management Framework (version 4). What's so good about WMF4? Why Powershell 4 is in it!
#http://download.microsoft.com/download/3/D/6/3D61D262-8549-4769-A660-230B67E15B25/Windows8-RT-KB2799888-x64.msu
if ($PSVersionTable.psversion.Major -ge 4)
{
write-host "Powershell 4 Installed already you don't need
this"
Exit-PSSession
}
$powershellpath = "C:\powershell"
function download-file
{
param ([string]$path, [string]$local)
$client = new-object system.net.WebClient
$client.Headers.Add("user-agent", "PowerShell")
$client.downloadfile($path, $local)
}
if (!(test-path $powershellpath))
{
New-Item -ItemType directory -Path $powershellpath
}
if (($PSVersionTable.CLRVersion.Major) -lt 4)
{
$DownloadUrl = "http://download.microsoft.com/download/B/A/4/BA4A7E71-2906-4B2D-A0E1-80CF16844F5F/dotNetFx45_Full_setup.exe"
$FileName = $DownLoadUrl.Split('/')[-1]
download-file $downloadurl "$powershellpath\$filename"
."$powershellpath\$filename"
}
#You may need to reboot after the .NET 4.5
install if so just run the script again.
if ([System.IntPtr]::Size -eq 4)
{
$DownloadUrl = "http://download.microsoft.com/download/3/D/6/3D61D262-8549-4769-A660-230B67E15B25/Windows6.1-KB2819745-x86-MultiPkg.msu"
}
Else
{
$DownloadUrl = "http://download.microsoft.com/download/3/D/6/3D61D262-8549-4769-A660-230B67E15B25/Windows6.1-KB2819745-x64-MultiPkg.msu"
}
$FileName = $DownLoadUrl.Split('/')[-1] download-file $downloadurl "$powershellpath\$filename"
."$powershellpath\$filename"
|
You can use this script to save you typing ".net 4.5 framework" and "windows management framework 4" into Google. It's got the Microsoft download URLs hardcoded, and we use our tricky
download-file function from weeks ago. Which is the great thing about getting into scripting, you really only have to solve a particular problem once! When the solution is in your script repository you can clone your own work!
The bulk of this script is just checking what .net and powershell versions are installed continuing or breaking depending on that. This should be familiar territory if you've been following along for the past 6 weeks.
We do check the Environment and check if we're running a 64bit version of windows then download the correct WMF file for your OS. That's a bit tricky.
We've also included the WMF for windows 8 so if you've got it installed you can copy and paste that into the $downloadurl (while you wear a potplant for a hat you mad windows 8 bugger you).