Script Purpose:

This Powershell script is written with the specific purpose, we have faced internal problems after pushing the latest October updates to our Server 2012 R2 infrastructure.

Proof of concept: Operating System changed network adapter profile or by Powershell -  NetworkCategory from "DomainAuthenticated" to "Private" or "Public".

Issue description: After applying updates, servers began disappearing from the monitoring system and application servers that were using SQL databases were unable to connect.


Script Description: 

Script will be executed against all server operating systems found in Active Directory with Enabled status. Script will check network adapters with Public or Private NetworkCategory  attribute with active internet connection.

Script will disable and enable found adapters(fastest fix that I found), and get connection back to Domain Profile, everything will be executed in Disconnected Session because we do not wan't to wait for Powershell to try to reconnect to destination machine after disabling/enabling network adapter.



ActiveDirectory Module

Domain Admin rights

# Script written by - Nemanja Jovic 
# Personal contact informations; Email - ; Skype - nemanja.jovic_1 
$Serverlist = Get-ADComputer -Filter 'OperatingSystem -like "*Server*"' -Properties * | Where Enabled -eq $True | Select-Object -ExpandProperty DNSHostName | Sort-Object DNSHostName 
foreach ($Server in $Serverlist) { 
Invoke-Command -ComputerName $Server -InDisconnectedSession -ScriptBlock { 
    $NetProfile = Get-NetConnectionProfile | where {$_.NetworkCategory -like "*Private*" -or $_.NetworkCategory -like "*Public*" -and $_.IPv4Connectivity -like "*Internet*"| Select-Object NetworkCategory,IPv4Connectivity 
    if ($NetProfile.IPv4Connectivity -like "*Internet*") { 
        Get-NetAdapter -name $($NetProfile.InterfaceAlias) | Disable-NetAdapter -Confirm:$False ; get-netadapter -name $($NetProfile.InterfaceAlias) | Enable-NetAdapter -Confirm:$False 
    Else {Continue}