Private/New-CustomAzNetworkInterface.ps1

function Global:New-CustomAzNetworkInterface{
    [CmdletBinding()]
    <#
    .SYNOPSIS
        Creates a new AzNetworkInterface, if not already existing
    .DESCRIPTION
        ...
    #>

    param(        
        [Parameter(Mandatory = $true, Position = 0)]
        [string]
        $ResourceGroupName,        
        [Parameter(Mandatory = $true, Position = 1)]
        [string]
        $ResourceLocation,
        [Alias("NicName")]
        [Parameter(Mandatory = $true, Position = 2)]
        [string]
        $Name,
        [Alias("NetworkInterfacePrivateIP")]
        [Parameter(Mandatory = $false, Position = 2)]
        [string]
        $NicPrivateIP,
        [Alias("VirtualNetworkName")]
        [Parameter(Mandatory = $true, Position = 2)]
        [string]
        $VNetName,
        [Parameter(Mandatory = $true, Position = 2)]
        [string]
        $SubnetName,
        [Alias("PublicIPName")]
        [Parameter(Mandatory = $false, Position = 2)]
        [string]
        $PipName,
        [Alias("PublicIPDomainNameLabel")]
        [Parameter(Mandatory = $false, Position = 2)]
        [string]
        $PipDnsLabel,
        [HashTable]
        $Tags
    )
    # Check if PublicIPInterface needs to be created
    if (-not([string]::IsNullOrEmpty($PipName))){
        if ([string]::IsNullOrEmpty($PipDnsLabel)){
            throw "DomainNameLabel 'PipDnsLabel' may not be empty, if you want to create a PublicIPInterface $PipName"
        }
        $PIP = Get-AzPublicIpAddress -Name $PipName -ResourceGroupName $ResourceGroupName -ErrorAction SilentlyContinue
        if (-not($PIP)){
            Write-CustomHost -Message "Creating PublicIP-interface $PipName..."
            $PIP = New-AzPublicIpAddress -Name $PipName -DomainNameLabel $PipDnsLabel -ResourceGroupName $ResourceGroupName -Location $ResourceLocation -AllocationMethod Dynamic -Tag $Tags
            Write-CustomHost -Message "PublicIP-interface $PipName created."
        }
    }

    # Get VNet
    Write-CustomHost -Message "Getting VirtualNetwork $VNetName..."
    $vnet = Get-AzVirtualNetwork -Name $VNetName -ResourceGroupName $ResourceGroupName

    # Create NIC
    Write-CustomHost -Message "Checking if NetworkInterface $Name needs to be created..."
    $NIC = Get-AzNetworkInterface -Name $Name -ResourceGroupName $ResourceGroupName -ErrorAction SilentlyContinue
    if (-not ($NIC)){
        Write-CustomHost -Message "Creating NetworkInterface $Name..."
        if ([string]::IsNullOrEmpty($NicPrivateIP)){    
            if ($PIP){
                $NIC = New-AzNetworkInterface -Name $Name -ResourceGroupName $ResourceGroupName -Location $ResourceLocation -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $PIP.Id -Tag $Tags
            } else {
                $NIC = New-AzNetworkInterface -Name $Name -ResourceGroupName $ResourceGroupName -Location $ResourceLocation -SubnetId $vnet.Subnets[0].Id -Tag $Tags
            }
        } else {
            $subnet = Get-AzVirtualNetworkSubnetConfig -Name $SubnetName -VirtualNetwork $vnet -ErrorAction SilentlyContinue
            if ($PIP){
                $IPconfig = New-AzNetworkInterfaceIpConfig -Name "$($Name)-config" -PrivateIpAddressVersion IPv4 -PrivateIpAddress $NicPrivateIP -SubnetId $subnet.Id -PublicIpAddressId $PIP.Id
            } else {
                $IPconfig = New-AzNetworkInterfaceIpConfig -Name "$($Name)-config" -PrivateIpAddressVersion IPv4 -PrivateIpAddress $NicPrivateIP -SubnetId $subnet.Id
            }
            $NIC = New-AzNetworkInterface -Name $Name -ResourceGroupName $ResourceGroupName -Location $ResourceLocation -IpConfiguration $IPconfig  -Tag $Tags
            Write-CustomHost -Message "Created network interface $Name"
        }
    } else {
        Write-CustomHost -Message "Network interface $Name already created"
    }
    return $NIC
}