Created
September 1, 2016 22:36
-
-
Save mikebranstein/0a8cd15ea3c596c7ffccc74fdc3469a2 to your computer and use it in GitHub Desktop.
Disable SoftAP on Windows 10 IoT Core with REST API calls with powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$retryLimit = 10 | |
$retryCount = 1 | |
$noError = $false | |
while ($noError -eq $false -and $retryCount -le $retryLimit) | |
{ | |
#Check for a 500 error on /api/iot/iotonboarding/softapsettings call | |
try{ | |
$responseSoftAP = Invoke-AuthenticatedWebRequest -uri "$apiRoot/iot/iotonboarding/softapsettings" -userName $username -password $password -method "GET" -contentType "" | |
} | |
catch { | |
Write-Host "There was an error... Retrying:" | |
Write-Host "Retry Count: $retryCount" | |
# Restart Device | |
Write-Host "Restarting Device $deviceName" | |
Invoke-Command -Session $session -FilePath .\Reboot-Device.ps1 | |
# wait for reboot of the device | |
Write-Host "Sleeping for 120 seconds while the device reboots..." | |
Start-Sleep -Seconds 120 | |
# re-establish the session | |
Write-Host "Done sleeping, resuming..." | |
Write-Host "Re-establishing remote powershell session..." | |
$session = New-PSSession -computer $deviceName -Credential $cred -ErrorAction Stop -SessionOption $pstimeout | |
$retryCount += 1 | |
Continue | |
} | |
$noError = $true | |
} | |
Write-Host "No More Errors!" | |
#This happens because we believe it provisions the SoftAP and needs a reboot for it to be set up correctly | |
Write-Host "Disabling SoftAP" | |
$softApEnabled = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("false")) | |
$softApSsid = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("SoftAPSsid")) | |
$softApPassword = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("[Password]")) | |
Invoke-AuthenticatedWebRequest -uri "$apiRoot/iot/iotonboarding/softapsettings?SoftAPEnabled=$softApEnabled&SoftApSsid=$softApSsid&SoftApPassword=$softApPassword" -userName $username -password $password -method "POST" -contentType "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment