Windows 2012 R2 : Configure a Network Adapter Using PowerShell

In my quest to automate Windows 2012 R2 deployment (along with SQL 2014 and SharePoint 2013) I wanted to simplify the static IP addressing of my deployed VMs. The following PowerShell commands below will configure the default Network Adapter – always named “Ethernet” in a standard windows 2012 R2 deployment – the script can be easily modified to suit your environment/IP addressing requirements:

$nic = Get-NetAdapter -Name Ethernet
$nic | Set-NetIPInterface -Dhcp Disabled
$nic | New-NetIPAddress -IPAddress -PrefixLength 24 –DefaultGateway
Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses ""

Windows 2012 R2 : Script to Rename Computer Based Upon Hyper-V Guest Name

I came across the following TechNet post recently which is useful for deploying Hyper-V machines and automating machine renaming to be in-line with the names given to you Hyper-V guests:

However, I ran into issues when testing on a Windows 2012 R2 Hyper-V Server and Windows 2012 R2 guest, so modified the rename component as follows – ensure you run from within the guest Operating System:

$virtualmachinename= (Get-ItemProperty 'HKLM:\software\microsoft\virtual machine\guest\parameters').virtualmachinename 
Rename-Computer -NewName $virtualmachinename.ToUpper()

Windows 2012 R2 : Forgot to Install the GUI?

In automating the deployment of some Windows 2012 R2 servers on a lab I neglected to select the ‘with GUI’ option during Windows Setup, use the script below to restore the GUI:

Install-WindowsFeature Server-Gui-Mgmt-Infra, Server-Gui-Shell -Source:wim:D:\sources\install.wim:2

SharePoint 2013 : Script to Download Pre-Requisites for Offline Install

In automating a SharePoint 2013 SP1 deployment on Windows Server 2012 R2 I came across the following PowerShell script to facilitate offline deployment of all Shareoint 2013 SP1 pre-requisites:

The only issue with this script is that it is for Windows 2012 / SharePoint 2013 RTM only.

The modified copy below facilitates all Windows 2012 R2 / SharePoint 2013 SP1 pre-requisite downloads – including naming of the downloads as required by the pre-requisite installer.

{code lang:text showtitle:false lines:false hidden:false}#***************************************************************************************
# Written by Craig Lussier -
# Udated for Windows 2012 R2/SharePoint 2013 SP1 by Chris Bradford -
# This script downloads SharePoint 2013 Prerequisites
# -Only run this script on Windows Server 2012 (RTM, either Standard or Datacenter)
# -Do not run this script on a Windows Server 2008 R2 SP1 Server!
# ---These are the Prerequisites for Windows Server 2012
# -Run this script as a local server Administrator
# -Run PowerShell as Administrator
# Don't forget to: Set-ExecutionPolicy RemoteSigned
# If you have not done so already within you Windows Server 2012 server
param([string] $SharePoint2013Path = $(Read-Host -Prompt "Please enter the directory path to where you wish to save the SharePoint 2013 Prerequisite files."))

# Import Required Modules
Import-Module BitsTransfer

# Specify download url's for SharePoint 2013 prerequisites
$DownloadUrls = (
         "", # Microsoft SQL Server 2008 R2 SP1 Native Client
         "", # Microsoft Sync Framework Runtime v1.0 SP1 (x64)
         "", # Windows Server App Fabric
         "", # CU 1 for AppFabric 1.1 (KB2671763)
         "", # Cumulative Update Package 1 for Microsoft AppFabric 1.1 for Windows Server (KB2671763)
         "", #Windows Identity Foundation (KB974405)
         "", # Microsoft Identity Extensions
         "", # Microsoft Information Protection and Control Client
         "", # Microsoft WCF Data Services 5.0
         "" # Microsoft WCF Data Services 5.6 (rename this download to WcfDataServices56.exe)

function DownLoadPreRequisites() {
	Write-Host ""
	Write-Host "====================================================================="
	Write-Host " Downloading SharePoint 2013 Prerequisites Please wait..."
	Write-Host "====================================================================="
	$ReturnCode = 0

	foreach ($DownLoadUrl in $DownloadUrls) {
		## Get the file name based on the portion of the URL after the last slash
		If ($DownloadUrl -eq "") {$filename = "WcfDataServices56.exe"}
    Else {$FileName = $DownLoadUrl.Split('/')[-1]}

	Try {
		## Check if destination file already exists
		If (!(Test-Path "$SharePoint2013Path\$FileName")){
			## Begin download
			Start-BitsTransfer -Source $DownLoadUrl -Destination $SharePoint2013Path\$fileName -DisplayName "Downloading `'$FileName`' to $SharePoint2013Path" -Priority High -Description "From $DownLoadUrl..." -ErrorVariable err
		If ($err) {Throw ""}}
		Else {
			Write-Host " - File $FileName already exists, skipping..."
		Catch {
			$ReturnCode = -1
			Write-Warning " - An error occurred downloading `'$FileName`'"
			Write-Error $_
	Write-Host " - Done downloading Prerequisites required for SharePoint 2013"
	return $ReturnCode

function CheckProvidedDownloadPath() {
	$ReturnCode = 0
	Try {
		# Check if destination path exists
		If (Test-Path $SharePoint2013Path) {
			# Remove trailing slash if it is present
			$script:SharePoint2013Path = $SharePoint2013Path.TrimEnd('\')
			$ReturnCode = 0
	Else {
		$ReturnCode = -1
		Write-Host ""
		Write-Warning "Your specified download path does not exist. Please verify your download path then run this script again."
		Write-Host ""
	Catch {
		$ReturnCode = -1
		Write-Warning "An error has occurred when checking your specified download path"
		Write-Error $_
	return $ReturnCode

function DownloadPreReqs() {
	$rc = 0
	$rc = CheckProvidedDownloadPath
	# Download Pre-Reqs
	if($rc -ne -1) {
		$rc = DownLoadPreRequisites
	if($rc -ne -1) {
		Write-Host ""
		Write-Host "Script execution is now complete!"
		Write-Host ""


SharePoint 2013 : Disable SSL on Central Administration

I’ve been testing the AutoSPinstaller recently and ran into an issue where I’d set the “Use SSL” flag on the Central Admin configuration, but had no certificate/didn’t actually want it to use SSL.

I figured I’d just run Set-SPCentralAdministration -Port <PortNumber> to resolve this issue – however this doesn’t change any of the AAMs, notably the default AAM for Central Admin.

Using the PowerShell script I found in the following blog post, the issue was resolved:

Be sure to change the URL and port number to suit your requirements.

#Load the SharePoint assembly

#Get the central admin webapp
$cAdmApp = [Microsoft.SharePoint.Administration.SPAdministrationWebApplication]::Local

#Create a new alternate url
$altUrl = New-Object "Microsoft.SharePoint.Administration.SPAlternateUrl" -ArgumentList "http://sp2013:8010", "Default"

#Set this alternate url as response url
$cAdmApp.AlternateUrls.SetResponseUrl( $altUrl )

#Get the alternate urls definition, this should only list our //http://server:10000 url

ConfigMgr : Windows 7 x64 OSDComputerName Ignored

We’ve been tetsing a 64-bit build of Windows 7 SP1, that includes IE 10. SCCM 2012 R2 CU1 performs both the Build and Capture Task Sequence alongside all Deployments of the ‘golden image’ to client devices.

The symptoms of this issue were simple, all “Deploy” Task Sequences were failing – on closer inspection it was clear that the machine had not joined the domain, and it had not used the hostname as defined in the OSDComputerName Task Sequence Variable – in fact the machine was using the name of the machine that we used to perform the golden image creation under the Build/Capture Task Sequence!

Having reviewed the sysprep logs on the client there was an error; SYSPRP LaunchDll:Could not load DLL C:\Windows\SysWOW64\iesysprep.dll[gle=0x000000c1]

This was surprising as the Build and Capture Task Sequence was completing successfully, every time.

Continue reading “ConfigMgr : Windows 7 x64 OSDComputerName Ignored”

SharePoint 2013 : IIS Default Landing Pages / 404 Errors and the Request Management Service

This was an interesting one I came across recently; intermittently we would get reports of users receiving 404 errors and IIS default landing pages, as if SharePoint sites were not running/working on our Web Front End servers.

The SharePoint environment was 2x WFE, 2x Service Application and 1x SQL Server Reporting Services. The WFE servers were load balanced by a HLB. We’re using Host Named Site Collections, so have to manually configure IIS bindings on the Web Front End servers.

There were few errors that really explained what was going on – initially we thought it was a backup related issue, but I think that the backup simply exacerbated the issue rather than caused the issue.

Just prior to raising a support call with Microsoft I came aross the following blog post, which was pretty much like-for-like what we were seeing on our SharePoint 2013 farm:

The issue was pretty simple – the Request Management Service was proxying requests to other servers in the farm – noteably the Service Application and SSRS servers – where IIS is not configured for the HNSCs. On the Service Application servers we had an IIS site listening on all all IPs/host headers, HTTPS – this was for Central Admin. On the SSRS server there was no HTTPS provision – this explained the randome behaviour we were seeing:

  • IIS landing page on the HTTPS-enabled Service Application servers
  • 404 errors on the non-HTTPS enabled SSRS server

Running some simple PowerShell commands we were able to exclude the Service Application and SSRS servers as targets from the Request Management Service configuration – commands taken from the blog above:

$web=Get-SPWebApplication -Identity <URL of web application>

$rm=Get-SPRequestManagementSettings -Identity

$web $m=Get-SPRoutingMachineInfo -RequestManagementSettings $rm -Name <MachineName> Set-SPRoutingMachineInfo -Identity $m -Availability Unavailable

No need to perform an IIS reset, the commands take effect immediately. Alongside resolving the IIS default page/404 errors, we also noticed that the HNSCs loaded significantly faster after making this change.

More info on the Request Management Service here:

SharePoint 2013 : Config Database Large Log File Size

By default the SharePoint 2013 Content Database is set to Full recovery mode – despite reccomendations from MS that this should be set to simple, as outlined here;

If unnoticed, you may find your Transaction Log volumes running short on disk space, as we did this morning, follow these steps to relieve storage pressure:

  1. Open SQL Server Management Studio and connect to the SQL Database Instance associated with your SharePoint farm
  2. Find the CONFIG database and right-click | Properties
  3. Under the options tree, change the recovery model to simple and click OK
  4. Again, right-click the CONFIG database | Tasks | Back Up – perform a backup of the CONFIG database
  5. Finally,right-click the CONFIG database | Tasks | Shrink | Files  – select Log under the “File Type” drop-down

It may be worth reviewing your recover models in-line with the URL above, for us it was just the CONFIG database that wasn’t in-line with MS recommendations.

SharePoint 2013 : Reduce Cumulative Update Installation Time

When upgrading our SharePoint 2013 environment to the June 2014 update we noted installation times in excess of four hours, so when it came to the September update we looked into how we could (if possible) reduce the installaion and deployment time.

I came across the following technet post which reduced installation time significantly on our farms: