forked from cisagov/ScubaGear
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAllowBasicAuthentication.ps1
57 lines (46 loc) · 1.56 KB
/
AllowBasicAuthentication.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#Requires -RunAsAdministrator
<#
.SYNOPSIS
Set Registry to allow basic authentication for WinRM Client
.DESCRIPTION
Run this script to enable basic authentication on your local desktop if you get an error when connecting to Exchange Online.
.NOTES
See README file Troubleshooting section for details.
This script requires administrative privileges on your local desktop and updates a registry key.
#>
function Test-RegistryKey {
<#
.SYNOPSIS
Test if registry key exists
#>
param (
[parameter (Mandatory = $true)]
[ValidateNotNullOrEmpty()]$Path,
[parameter (Mandatory = $true)]
[ValidateNotNullOrEmpty()]$Key
)
try {
Get-ItemProperty -Path $Path -Name $Key -ErrorAction Stop | Out-Null
return $true
}
catch {
return $false
}
}
$regPath = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WinRM\Client'
$regKey = 'AllowBasic'
if (-Not $(Test-Path -LiteralPath $regPath)) {
New-Item -Path $regPath -Force | Out-Null
New-ItemProperty -Path $regPath -Name $regKey | Out-Null
} elseif (-Not $(Test-RegistryKey -Path $regPath -Key $regKey)) {
New-ItemProperty -Path $regPath -Name $regKey | Out-Null
}
try {
$allowBasic = Get-ItemPropertyValue -Path $regPath -Name $regKey -ErrorAction Stop
if ($allowBasic -ne '1') {
Set-ItemProperty -Path $regPath -Name $regKey -Type DWord -Value '1'
}
}
catch {
Write-Error -Message "Unexpected error occured attempting to update registry key, $regKey."
}