PowerShell advanced function (cmdlet) – Report all VMs with disconnected NICs in the specified Virtual Machine Manager


This is very simple function to report all virtual machines in the defined System Center Virtual Machine Manager (SCVMM) with disconnected network adapters or with network adapters without specified VLAN.

Examples

Report

Get-RvSCVirtualNetworkAdapter -VMMServer firstVMM, secondVMM, thirdVMM -NoVMNetworkOrNoVLan | Out-GridView

Code

Function Get-RvSCVirtualNetworkAdapter
{
    <#
    .SYNOPSIS
        Get network adapters of virtual machine on defined SCVMM server.

    .DESCRIPTION
        Developer
            Developer: Rudolf Vesely, http://rudolfvesely.com/
            Copyright (c) Rudolf Vesely. All rights reserved
            License: Free for private use only

            "RV" are initials of the developer's name Rudolf Vesely and distingue names of Rudolf Vesely's cmdlets from the other cmdlets.

        Description
            Get network adapters of virtual machine on defined SCVMM server.

        Requirements
            Developed and tested using PowerShell 4.0.

    .PARAMETER NoVMNetwork
        Get only disconnected NICs (no network).

    .PARAMETER NoVLan
        Get only NICs without specified VLAN.

    .EXAMPLE
        Get-RvSCVirtualNetworkAdapter -VMMServer firstVMM, secondVMM, thirdVMM -NoVMNetworkOrNoVLan |
            Format-Table -Property Name, VirtualNetwork, LogicalNetwork, LogicalSwitch, VMNetwork, VLanEnabled, VLanID -AutoSize

    .INPUTS

    .OUTPUTS

    .LINK
        https://techstronghold.com/
    #>

    [CmdletBinding(
        DefaultParametersetName = 'All',
        SupportsShouldProcess = $true,
        PositionalBinding = $false,
        HelpURI = 'https://techstronghold.com/',
        ConfirmImpact = 'Medium'
    )]

    Param
    (
        [Parameter(
            Mandatory = $false,
            # Position = ,
            ParameterSetName = 'All'
        )]
        [switch]$All,

        [Parameter(
            Mandatory = $false,
            # Position = ,
            ParameterSetName = 'NoVMNetwork'
        )]
        [switch]$NoVMNetwork,

        [Parameter(
            Mandatory = $false,
            # Position = ,
            ParameterSetName = 'NoVLan'
        )]
        [switch]$NoVLan,

        [Parameter(
            Mandatory = $false,
            # Position = ,
            ParameterSetName = 'NoVLan'
        )]
        [switch]$NoVMNetworkOrNoVLan,

        [Parameter(
            Mandatory = $false
            # Position = ,
            # ParameterSetName = ''
        )]
        [ValidateLength(1, 255)]
        [string[]]$VMMServer = '.'
    )

    Begin
    {
        # Configurations
        $ErrorActionPreference = 'Stop'
        if ($PSBoundParameters['Debug']) { $DebugPreference = 'Continue' }
        Set-PSDebug -Strict
        Set-StrictMode -Version Latest
    }

    Process
    {
        foreach ($vmmServerItem in $VMMServer)
        {
            Get-SCVirtualNetworkAdapter -All | ForEach-Object -Process `
            {
                if ($NoVMNetwork)
                {
                    if (!$_.VirtualNetwork -or !$_.VMNetwork) { $_ }
                }
                elseif ($NoVLan)
                {
                    if (!$_.VLanEnabled -or !$_.VLanID) { $_ }
                }
                elseif ($NoVMNetworkOrNoVLan)
                {
                    if (!$_.VLanEnabled -or !$_.VLanID -or !$_.VirtualNetwork -or !$_.VMNetwork) { $_ }
                }
                else
                {
                    $_
                }
            }
        }
    }

    End
    {
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Active Directory Advanced function AlwaysOn Availability Groups AlwaysOn Failover Cluster Instances Building Cloud Cloud Cluster Cmdlet Database Deployment Design DFS Domain Controller DSC Fabric Failover Clustering File Server Group Policy Hardware Profile Host Hyper-V Installation Library Library Asset Library Server Network Operations Manager Orchestrator PowerShell PowerShell User Group PowerShell Workflow Security Service Manager SQL Server Storage System Center Template Time Time Synchronization Tips Virtual Machine Virtual Machine Manager VM Network VM Template Windows Server 2012 R2