Wednesday, November 18, 2015

Network interface management on multiple servers with PowerShell

Here is couple of PowerShell scripts were useful in my recent activity with some lab. 
PowerShell script that Enables or Disables required network interfaces on multiple servers:
$NICsToModify = "Live Migration","Cluster-CSV"
$servers="server1","server2","server3","server4","server5","server6"

foreach ($server in $servers)
    {
    $cimsession=New-CimSession -ComputerName $server
    # Uncomment/comment required row
    Enable-NetAdapter -Name $NICsToModify -CimSession $cimsession
    # Disable-NetAdapter -Name $NICsToModify -CimSession $cimsession –Confirm:$false
    }    
PowerShell script that marks required Network Team NIC members as Passive or Active on multiple servers:
$TeamNICMembersToModify = "Port2","Port1"
$servers="server1","server2","server3","server4","server5","server6"
foreach ($server in $servers)
    {
    $cimsession=New-CimSession -ComputerName $server
    # Uncomment/comment required row
    # Set Team NIC member to "Active" mode
    Set-NetLbfoTeamMember -Name $TeamNICMembersToModify -AdministrativeMode Active -CimSession $cimsession
    # Set Team NIC member to "Standby" mode
    # Set-NetLbfoTeamMember -Name $TeamNICMembersToModify -AdministrativeMode Standby -CimSession $cimsession
    }