Deploying Backup Agent Using PowerShell

init
(MBS Console > Setting > General > Company) MBS Company Name:
$CompanyName = "MyCompany"
(MBS Console > Setting > General > Product Name) Product Name:
$ProductName = "MyProduct" 
## (MBS Console > Setting > General > API 2.0 Credentials) API creds:
$Body = @{ 
    UserName = 'api_user'
    Password = 'api_password'
}
(MBS Console > Downloads) Install type = Windows, Virtual Machine Edition, Dedup Server, (Red Hat, Fedora, CentOS, SUSE, Oracle Linux), macOS, Ubuntu
$InsallType = "Windows"
(MBS Console > Users) User info:
$UserCreds = @{
    Email = "user"
    Password = "password"
}
download to directory:
$DownloadTo = "c:\backup\"
Log folder
$LogFolder = "C:\Logs\"
############################################################do
$date = (Get-Date).ToUniversalTime().ToString("yyyyMMddHHmmss") ##get date
$LoginResponse = Invoke-WebRequest 'https://api.mspbackups.com/api/provider/login' -SessionVariable 'Session' -Body $Body -Method 'POST' ##login to MBS
$AccessToken = ($LoginResponse.Content | ConvertFrom-Json).access_token
##get builds and link
$BuildsResponse = Invoke-RestMethod -URI 'https://api.mspbackups.com/api/builds' -Method Get -Headers @{"accept"="application/json";"Authorization" = "Bearer " + $AccessToken}
$link = $BuildsResponse | Where {$_.Type -like $InsallType} | Select -ExpandProperty DownloadLink 
if (($InsallType -eq "macOS") -or ($InsallType -eq "Ubuntu") -or ($InsallType -eq "Red Hat, Fedora, CentOS, SUSE, Oracle Linux"))
{##non-Windows package
     echo ("Installation package is incompatible. Terminating.") >> ($LogFolder + $date + ".log")
} 
else
{##install Windows package
    if (!(Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall* |  Select-Object DisplayName | where DisplayName -Like ("*" + $ProductName + "*")))
    {##not installed
        mkdir $DownloadTo -Force
        cd $DownloadTo
        ##download
        Invoke-WebRequest $link -OutFile ($temp = Split-Path $link -Leaf)
        Start-Process $temp -ArgumentList "/S" -Wait ##install
        cd ($path = "C:\Program Files\" + $CompanyName + "\" + $ProductName + "\") 
        $arglist = "addAccount -e " + $UserCreds.Email + " -p " + $UserCreds.Password
        start-process -FilePath ($path + "cbb.exe") -ArgumentList $arglist -RedirectStandardOutput ($LogFolder + $date + ".log") ##set creds
        ##delete unnecessary
        Remove-Item $DownloadTo -Recurse -Force
    }
    else
    {##already deployed
        echo ("Already deployed. Use auto-update feature to update the application.") >> ($LogFolder + $date + ".log")
    }    
}
#*****************************************************************************************************