Search
  • Shannon

Internet Explorer Automation - Pt. 2 Installing Edge

In my last post, I built out a quick script to remove Internet Explorer from Windows servers. Now that Internet Explorer has effectively retired, it's time to remove the installation completely. Seeing as I didn't want to log into every server I maintain for demos, I decided to automate as much as I could within the full process.


Next up? I needed to download a Microsoft Edge MSI or EXE to push out to all machines and install using a ForEach loop via PowerShell. After searching online, I came across Mattias Benninge's blog post where he discusses creating a sample PowerShell script that can be used to download either a specific version of a channel or the latest available version. This script only downloads the Edge MSI for the specified channel but can easily be extended into Configuration Manager or a script based installation (like my demo servers).


I ran the following script on my utilis server:

.\Get-EdgeEnterpriseMSI.ps1 -Channel Stable -Folder \\shanutils\Utils\Software\Edge-Chromium -Force

Then I located that folder and noticed a MicrosoftEdgeEnterpriseX64.msi sitting there:

Sweet - now I can get PowerShell to do the rest!


There are a few things you need to ensure and I actually didn't cover this in my last post. WinRM (or Windows Remote Management) needs to be running on the servers you intend to install Edge Chromium remotely. Additionally, most operating systems in the server class of Microsoft should work, but I'm throwing in the pre-reqs for server OS related to the install as well.


Next up, the script! I never dabbled in the realm of System Center Configuration Manager, so I tended to maintain state in a variety of different ways previously (many of which were manual until I found myself getting better and better with PowerShell). I definitely want to stress there are a bunch of ways to tackle this problem that are probably more sophisticated than what I did, but know it can be done like this if you manage a bunch of servers and there's no graceful way for you to manage state.


I went ahead and queried Active Directory again in my script. I set a variable with all computers in AD that have Windows for the installation. I then store the source path as a variable (i.e. where I'm taking the .msi from) and then I ForEach looped through all the servers. The script itself takes the .msi on my utils server, copies it to the C drive of each server queried from Active Directory, invokes a session to each server, and creates a new object and specifies a set of values that are used to start the process of installing the Edge application. I pass in where the .msi is located and the commands to start installing the application in a quiet fashion. Interestingly enough, I didn't realize this way of building a PowerShell script is actually leaning on C#. I should save my C# blogs for later on, but I keep saying that if system administrators who didn't have a college degree in Computer Science took a very bare bones intro to C# class, they'd understand PowerShell a helluva lot more.


Without further ado, here's the script on GitHub and take a peek below, if you prefer to copy/paste:

Import-Module ActiveDirectory
$servers = Get-ADComputer -Filter {OperatingSystem -like "*Windows*"}
$sourcePath = "\\shanutils\Utils\Software\Edge-Chromium\MicrosoftEdgeEnterpriseX64.msi"
ForEach ($server in $servers){
    Copy-Item -Path $sourcePath -Destination \\$($server.Name)\c$\ -Verbose -WarningAction Ignore -ErrorAction Ignore
    $session = New-PSSession -ComputerName $server.DNSHostName
        Invoke-Command -Session $session -ScriptBlock {
            $process = New-Object System.Diagnostics.Process  
            $process.StartInfo.FileName = "C:\MicrosoftEdgeEnterpriseX64.msi"
            $process.StartInfo.Arguments = " /qn"
            $process.Start()             
    }
    Enter-PSSession -Session $session 
    Exit-PSSession
    Write-Host -ForegroundColor Green Installed Microsoft Edge on $server.DNSHostName
}

That's it! I have taken you through the quick ways I wound up getting my environments current with the removal of Internet Explorer. By no means is this "production ready". I more so build out blog posts to give you a starting point or help you learn how to automate more within your world. Take what I've done, experiment, and build out an even more robust script! I dare you! And then tag me with your final script. I'd love to see how far you take your version! Cheers and happy PowerShelling!

290 views0 comments

Recent Posts

See All