# usage: .\disable-call-to-home.ps1 -ProfileUnityUrl "https://localhost:8000" -Username "xxx" -Password "yyy" # usage: .\disable-call-to-home.ps1 -ProfileUnityUrl "https://localhost:8000" -Username "xxx" -Password "yyy" -Enable $true # this script authenticates against the api, and then sets the "call to home" setting to true or false. # note that you must then restart the service for the change to take effect param( [Parameter(Mandatory=$true)] [string]$ProfileUnityUrl, [Parameter(Mandatory=$true)] [string]$Username, [Parameter(Mandatory=$true)] [string]$Password, [Parameter(Mandatory=$false)] [bool]$Enable = $false ) # SSL setup add-type @" using System.Net; using System.Security.Cryptography.X509Certificates; public class TrustAllCertsPolicy : ICertificatePolicy { public bool CheckValidationResult( ServicePoint svcPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { return true; } } "@ [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 # Create web session with browser-like headers $session = New-Object Microsoft.PowerShell.Commands.WebRequestSession $session.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" try { # Step 1: Authenticate Write-Host "Authenticating with ProfileUnity..." -ForegroundColor Yellow $loginBody = "Username=$Username&Password=$Password" $loginResponse = Invoke-RestMethod -Uri "$ProfileUnityUrl/authenticate" -Method Post -Body $loginBody -ContentType "application/x-www-form-urlencoded" -WebSession $session if ($loginResponse.WebMessageType -eq 2) { Write-Host "Authentication successful!" -ForegroundColor Green # Step 2: Refresh settings cache to prevent "out of sync" errors Write-Host "Refreshing settings cache..." -ForegroundColor Yellow try { $refreshResponse = Invoke-RestMethod -Uri "$ProfileUnityUrl/api/server/Setting" -Method Get -WebSession $session Write-Host "Settings cache refreshed successfully!" -ForegroundColor Green } catch { Write-Host "Settings refresh failed, but continuing..." -ForegroundColor Yellow } # Step 3: Set the remote setting $action = if ($Enable) { "enabling" } else { "disabling" } $status = if ($Enable) { "enabled" } else { "disabled" } Write-Host "$action remote 'call to home' feature..." -ForegroundColor Yellow $settingsUri = "$ProfileUnityUrl/api/server/Setting/remote/enable?value=$($Enable.ToString().ToLower())" $settingsResponse = Invoke-RestMethod -Uri $settingsUri -Method Post -WebSession $session if ($settingsResponse.WebMessageType -eq 2) { Write-Host "Remote settings successfully $status!" -ForegroundColor Green Write-Host "Response: $($settingsResponse.Message)" -ForegroundColor Cyan Write-Host "NOTE you must restart the service for the change to take effect!" -ForegroundColor Cyan } else { Write-Host "Failed to update settings. Response: $($settingsResponse.Message)" -ForegroundColor Red # If we still get an out-of-sync error, try one more time with a fresh GET if ($settingsResponse.Message -like "*out of sync*") { Write-Host "Retrying with fresh settings cache..." -ForegroundColor Yellow try { $retryResponse = Invoke-RestMethod -Uri "$ProfileUnityUrl/api/server/Setting" -Method Get -WebSession $session $retrySettingsResponse = Invoke-RestMethod -Uri $settingsUri -Method Post -WebSession $session if ($retrySettingsResponse.WebMessageType -eq 2) { Write-Host "Remote settings successfully $status on retry!" -ForegroundColor Green Write-Host "Response: $($retrySettingsResponse.Message)" -ForegroundColor Cyan } else { Write-Host "Retry also failed. Response: $($retrySettingsResponse.Message)" -ForegroundColor Red } } catch { Write-Host "Retry failed: $($_.Exception.Message)" -ForegroundColor Red } } } } else { Write-Host "Authentication failed. Response: $($loginResponse.Message)" -ForegroundColor Red } } catch { Write-Host "Error occurred: $($_.Exception.Message)" -ForegroundColor Red } Write-Host "Script completed." -ForegroundColor Yellow