Generate-NetConf.ps1

# This script is utilzed to generate the required configurations for network devices based off input given by the user

#region Variable Declaration

New-Variable -Name deviceType -Scope Global
New-Variable -Name deviceNumber -Scope Global
New-Variable -Name deviceFunction -Scope Global
New-Variable -Name devicePortCount -Scope Global
New-Variable -Name site -Scope Global
New-Variable -Name managementIP -Scope Global
New-Variable -Name siteIPValue -Scope Global
New-Variable -Name secureStringSecret -Scope Global
New-Variable -Name secretPlainText -Scope Global
#endregion

Function Get-SiteNumber {
    do {
        Set-Variable -Name site -value (Read-Host -Prompt "Enter Site Number with 2 digits (eg. 08 or 12)") -scope Global

    } until (
        $site -match "^\d{2}$"
    )

}
Function Get-ManagementIP {

    do {

        Set-Variable -Name managementIP -Value (Read-Host -Prompt "Enter The Last octet of the management IP for the device") -scope Global
    
    } until (
        $managementIP -match "^\d{1,3}$"
    )
    

}
Function Get-DeviceType {

    do {
        Write-Host "===Device Type==="
        Write-Host "1. Cisco NX-OS Device"
        Write-Host "2. Cisco IOS-XE Device"
        Set-Variable -Name deviceType -value (Read-Host -Prompt "Enter Number from above") -scope Global
        
    } until (
        $deviceType -match "^[1-2]$"
    )

    do {
        Write-Host "===Device Ports==="
        Write-Host "1. 24 Ports"
        Write-Host "2. 48 Ports"
        Set-Variable -Name devicePortCount -value (Read-Host -Prompt "Enter Number from above") -scope Global
        
    } until (
        $devicePortCount -match "^[1-2]$"        
    )

    if ($devicePortCount -eq "1") {
        Set-Variable -Name devicePortCount -value "24" -Scope Global
    }
    elseif ($devicePortCount -eq "2") {
        Set-Variable -Name devicePortCount -value "48" -Scope Global
    }
}

Function Get-Secret {
    Set-Variable -Name secureStringSecret -Value (Read-Host -AsSecureString -Prompt "Enter Enable Secret") -scope Global

    Set-Variable -Name secretPlainText -value ($secureStringSecret | ConvertFrom-SecureString -AsPlainText) -Scope Global

}


Function Set-AAA {

    "aaa new-model"
    "aaa authentication login default local"
    "aaa authorization exec default local if-authenticated"
    "aaa authorization console"

    "username netadmin privlege 15 algorithm-type scrypt secret " + $secretPlainText
    "enable algorithm-type scrypt secret " + $secretPlainText

}

Function Set-Vlans {
    "vlan 998"
    "name v998.e" + $site + "-net-mgt"
    "exit"

    "vlan 3"
    "name v3.e" + $site + "-native"
    "exit"

    "vlan 15"
    "name v15.e" + $site + "-usr-tr"
    "exit"

    "vlan 26"
    "name v26.e" + $site + "-vvoip-tr"
    "exit"

    "vlan 27"
    "name v27.e" + $site + "-vvoip-tr"
    "exit"

    "vlan 30"
    "name v30.e" + $site + "-ptr-tr"
    "exit"
}

Function Set-Inital {

    $site -match "[1]{0,1}[1-9]{1}"

    $siteIPValue = $Matches[0]

    "conf t"
    "hostname E" + $site + "-" + $deviceFunction + "-" + $deviceNumber
    "ip domain-name us.net"
    "ip name-servers 10." + $siteIPValue + ".8.82" + " " + "10." + $siteIPValue + ".8.83"
    "ip ssh version 2"
    "crypto key generate rsa modulus 3072"

    "interface vlan 998"
    "Description v998.e" + $site + "-net-mgt"
    "ip address 172.17." + $siteIPValue + "." + $managementIP
    "no shutdown"
    "exit"
    "ip default-gateway 172.17." + $siteIPValue + ".1"
}

Function Set-Ports {
    Function Set-TrunkPort {
        "Description Uplink to ACS"
        "Switchport"
        "Switchport mode trunk"
        "Switchport trunk native vlan 3"
        "no shutdown"
        "exit"
    }
    Function Set-AccessPort {
        "Description Access Port"
        "Switchport"
        "Switchport mode access"
        "Switchport access vlan 15"
        "Switchport voice vlan 26"
        "spanningtree portfast edge"
        "no shutdown"
        "exit"
    }
    if ($deviceType -eq "EAS") {
        if ($devicePortCount -eq 24) {
            "interface range HundredGigabitEthernet1/0/25-26"
            Set-TrunkPort
            "Interface range Twe1/0/1-24"
            Set-AccessPort
        }
        if ($devicePortCount -eq 48) {
            "interface range HundredGigabitEthernet1/0/49-50"
            Set-TrunkPort
            "Interface range Twe1/0/1-48"
            Set-AccessPort
        }
    }
}

Get-SiteNumber
Get-ManagementIP
Get-Secret
Get-DeviceType
Set-Inital
Set-AAA
Set-Vlans
Set-Ports