<#
Solution: Hydration 
Purpose: Authorize - DHCP
Version: 1.2 -  Juin 2015 

Author - Jérôme Bezet-Torres
 
#>

# Determine where to do the logging 
$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment 
$logPath = $tsenv.Value("LogPath") 
$logFile = "$logPath\$($myInvocation.MyCommand).log" 

# Start the logging 
Start-Transcript $logFile 
Write-Host "Logging to $logFile"

$Interface = Get-NetAdapter -Name Ethernet0
$IFindex = Get-NetIPAddress -InterfaceIndex $Interface.ifIndex -AddressFamily IPv4
$IP = $IFindex.IPv4Address
    

      Add-DhcpServerInDC -DnsName $env:COMPUTERNAME -IPAddress $IP 

set-ItemProperty HKLM:\SOFTWARE\Microsoft\ServerManager\Roles\12 -name ConfigurationState -Value 0x000000002
set-ItemProperty HKLM:\SOFTWARE\Microsoft\ServerManager\Roles\10 -name ConfigurationStatus -Value 0x000000002

# Stop logging 
Stop-Transcript
