ADLAB PowerShell source file: buildup-rras.ps1

(C) Ondrej Sevecek, 2019 - www.sevecek.com, ondrej@sevecek.com



#$global:outClass = 'main'

$libDir = Split-Path -parent $MyInvocation.MyCommand.Definition
& "$libDir\lib-common.ps1" -defaultConfig -rootDir $libDir -outFile rrasLib
& "$libDir\lib-modifyActions.ps1"
& "$libDir\lib-buildup.ps1"

$vmName = $args[0]

DBG ("RRAS configuration library")
Redirect-TempToOutput
Load-VMConfig

Find-MarkedVolumes

$appTag = 'rras'
$appConfig = $vmConfig.$appTag
$firstAppHost = Get-FirstAppHostInInstance $appTag $appConfig.instance 'waitParams'
$firstAppHostInInstance = Check-FirstAppHostInInstance $appTag $appConfig.instance


#====================
#====================


Enable-RRAS (Parse-BoolSafe $appConfig.vpn)


DBG ('Should we enabled and configure the DHCP relay agent: {0}' -f (Is-ValidString $appConfig.dhcpRelay.server))
if (Is-ValidString $appConfig.dhcpRelay.server) {

  DBG ('Going to install the DHCP relay agent')

  Run-Process NETSH 'routing ip relay install'
  Run-Process NETSH 'routing ip relay set global loglevel=info'

  foreach ($oneDhcpServer in (Split-MultiValue $appConfig.dhcpRelay.server)) {

    if ($oneDhcpServer -like 'ref:?*') {

      $referredDhcpInstance = $oneDhcpServer.SubString(4)
      DBG ('Get the referred DHCP server: {0}' -f $referredDhcpInstance)

      $referedSvc = Get-FirstAppHostInInstance -appTag dhcp -instance $referredDhcpInstance -hostType svcConfig
      $referedMachine = Get-MachineFromElement $referedSvc

      DBG ('Get the IP address for the refered machine: {0}' -f $referedMachine.hostName)
      [object[]] $referedMachineIPs = $null
      $referedMachineIPs = Get-NetworkMap $referedMachine.hostName | ? { Is-EmptyString $_.nlbInstance }
      DBGIF $MyInvocation.MyCommand.Name { (Get-CountSafe $referedMachineIPs) -ne 1 }
      $dhcpServer = $referedMachineIPs[0].ipAddress

    } else {

      $dhcpServer = $oneDhcpServer
    }

    DBG ('Configure the DHCP relay agent to forward to DHCP server: {0}' -f $dhcpServer)
    Run-Process NETSH ('routing ip relay add dhcpserver {0}' -f $dhcpServer)
  }

  DBG ('Should we enable any interfaces in the DHCP relay agent: {0} | {1}' -f (Is-ValidString $appConfig.dhcpRelay.intf), $appConfig.dhcpRelay.intf)
  if (Is-ValidString $appConfig.dhcpRelay.intf) {

    foreach ($oneIntf in (Split-MultiValue $appConfig.dhcpRelay.intf)) {

      DBG ('Going to enable the DHCP relay agent for one interface: {0}' -f $oneIntf)
      # Note: maxhop maximum is 16
      Run-Process NETSH ('routing ip relay add interface name="{0}"' -f $oneIntf)
      Run-Process NETSH ('routing ip relay set interface name="{0}" relaymode=enable maxhop=16 minsecs=4' -f $oneIntf)
    }
  }
}
  



# SIG # Begin signature block
# MIIYMAYJKoZIhvcNAQcCoIIYITCCGB0CAQExDzANBglghkgBZQMEAgEFADB5Bgor
# BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG
# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCB7syoTcvucIUmn
# po0r6J8gLPUNf7N+T0sdZy8WBxMygqCCE0cwggYEMIID7KADAgECAgoqHIRwAAEA
# AAB/MA0GCSqGSIb3DQEBCwUAMGwxCzAJBgNVBAYTAkNaMRcwFQYDVQQIEw5DemVj
# aCBSZXB1YmxpYzENMAsGA1UEBxMEQnJubzEQMA4GA1UEChMHU2V2ZWNlazEjMCEG
# A1UEAxMaU2V2ZWNlayBFbnRlcnByaXNlIFJvb3QgQ0EwHhcNMTkwNjExMTkyMzMy
# WhcNMjQwNjA5MTkyMzMyWjCBjzELMAkGA1UEBhMCQ1oxFzAVBgNVBAgTDkN6ZWNo
# IFJlcHVibGljMQ0wCwYDVQQHEwRCcm5vMRwwGgYDVQQKExNJbmcuIE9uZHJlaiBT
# ZXZlY2VrMRcwFQYDVQQDEw5PbmRyZWogU2V2ZWNlazEhMB8GCSqGSIb3DQEJARYS
# b25kcmVqQHNldmVjZWsuY29tMIIBIjANBgkqh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