<#
# Set variables to indicate value and key to set
# https://devblogs.microsoft.com/powershell-community/how-to-update-or-add-a-registry-key-value-with-powershell/

#
# Registry key	Type	Value
# HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\15.0\Common\Identity\EnableADAL	REG_DWORD	1
# HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\15.0\Common\Identity\Version	REG_DWORD	1
# HKEY_CURRENT_USER\Software\Microsoft\Exchange\AlwaysUseMSOAuthForAutoDiscover	REG_DWORD	1
#>


date
$ComputerName = hostname
Write-Host "HOST NAME: $ComputerName"


$RegistryPath1 = 'HKCU:\Software\Microsoft\Office\15.0\Common\Identity'
$Name1         = 'EnableADAL'
$Value1        = '1'

# Create the key if it does not exist
If (-NOT (Test-Path $RegistryPath1)) {
  New-Item -Path $RegistryPath1 -Force | Out-Null
}  
# Now set the value
New-ItemProperty -Path $RegistryPath1 -Name $Name1 -Value $Value1 -PropertyType DWORD -Force 

#

$RegistryPath2 = 'HKCU:\Software\Microsoft\Office\15.0\Common\Identity'
$Name2         = 'Version'
$Value2        = '1'

# Create the key if it does not exist
If (-NOT (Test-Path $RegistryPath2)) {
  New-Item -Path $RegistryPath2 -Force | Out-Null
}  
# Now set the value
New-ItemProperty -Path $RegistryPath2 -Name $Name2 -Value $Value2 -PropertyType DWORD -Force 

#

$RegistryPath3 = 'HKCU:\Software\Microsoft\Exchange'
$Name3         = 'AlwaysUseMSOAuthForAutoDiscover'
$Value3        = '1'

# Create the key if it does not exist
If (-NOT (Test-Path $RegistryPath3)) {
  New-Item -Path $RegistryPath3 -Force | Out-Null
}  
# Now set the value
New-ItemProperty -Path $RegistryPath3 -Name $Name3 -Value $Value3 -PropertyType DWORD -Force 


# Now Restart Computer
Restart-Computer -Force