PowerShell Linphone Configuration

33 views Asked by At

I'm trying to do a massive deployment to many users, and I've creating this script, one of the functions into the script is, to verify the username of the machine, to match the current path of the linphone installation, etc, adittionally to this i have a bunch of content that we need to put into this file, I created a plain text file to verifiy if this script is writting into the file but it's not.

# Get the current user's name
$usuario = $env:USERNAME

# Check if Chocolatey is installed
$chocoPath = Get-Item -Path 'C:\ProgramData\chocolatey\bin\choco.exe' -ErrorAction SilentlyContinue

if (-not $chocoPath) {
    # If not installed, download and install it
    Write-Host "Chocolatey is not installed. Downloading and installing..."
    Set-ExecutionPolicy Bypass -Scope Process -Force; iwr https://community.chocolatey.org/install.ps1 -UseBasicParsing | iex
    $chocoPath = Get-Item -Path 'C:\ProgramData\chocolatey\bin\choco.exe' -ErrorAction SilentlyContinue
    if ($chocoPath) {
        Write-Host "Chocolatey installed successfully."
        $env:Path += ";C:\ProgramData\chocolatey\bin"
    } else {
        Write-Host "Error installing Chocolatey."
        exit
    }
} else {
    # If already installed, show a message
    Write-Host "Chocolatey is already installed."
}

# Check if Linphone is installed
$linphonePath = Get-Item -Path 'C:\Program Files\Linphone' -ErrorAction SilentlyContinue

if (-not $linphonePath) {
    # If not installed, install it using Chocolatey
    Write-Host "Linphone is not installed. Installing with Chocolatey..."
    choco install linphone -y
    $linphonePath = Get-Item -Path 'C:\Program Files\Linphone' -ErrorAction SilentlyContinue
    if ($linphonePath) {
        Write-Host "Linphone installed successfully."
    } else {
        Write-Host "Error installing Linphone."
        exit
    }
} else {
    # If already installed, show a message
    Write-Host "Linphone is already installed."
}

# Start Linphone
Start-Process "C:\Program Files\Linphone\bin\linphone.exe" -WindowStyle Hidden
Start-Sleep -Seconds 8

# Extract the current user's email from the obtained path
if ($linphonePath) {
    $pathcurrentuseremail = (Get-ItemProperty -Path Registry::HKCU\Software\Microsoft\OneDrive\Accounts\Business1 -Name "UserEmail" -ErrorAction SilentlyContinue).UserEmail
    if ($pathcurrentuseremail) {
        Write-Host "Current user's email: $pathcurrentuseremail"
    } else {
        Write-Host "Unable to find current user's email in the registry."
        exit
    }
}

# Path of the Linphone configuration file
if ($usuario) {
    $rutaConfiguracion = "C:\Users\pedro\AppData\Local\linphone\prueba.txt"
} else {
    Write-Host "Unable to get the current user's name."
    exit
}

# Load the list of emails, passwords, and usernames from a CSV file
$listaUsuarios = Import-Csv -Path "C:\Users\pedro\OneDrive\Escritorio\DESKTOP\juan\SCRIPTS\extensions.csv"

# Search for the email in the loaded list
$usuarioEncontrado = $listaUsuarios | Where-Object { $_.Email -eq $pathcurrentuseremail }

if ($usuarioEncontrado) {
    # Get the corresponding data
    $username = $usuarioEncontrado.Username
    $passwd = $usuarioEncontrado.Password
    $displayname = $usuarioEncontrado.DisplayName
    $extension = $usuarioEncontrado.Extension

    # Content to add to the configuration file
    $contenido = @"
[auth_info_0]
username=$username
passwd=$passwd
domain=192.168.0.1

[proxy_0]
reg_proxy=<sip:192.168.0.1;transport=udp>
reg_identity="$displayname" <sip:[email protected]>
quality_reporting_enabled=0
quality_reporting_interval=0
reg_expires=3600
reg_sendregister=1
publish=0
avpf=0
avpf_rr_interval=1
dial_escape_plus=0
use_dial_prefix_for_calls_and_chats=1
privacy=32768
push_notification_allowed=0
remote_push_notification_allowed=0
force_register_on_push=0
cpim_in_basic_chat_rooms_enabled=0
idkey=proxy_config_U9B64IIcxmY~wfM
publish_expires=-1
rtp_bundle=0
rtp_bundle_assumption=0
"@

    # Add the content to the configuration file
    Add-Content -Path $rutaConfiguracion -Value $contenido

    # Check if the writing was successful
    if (-not (Test-Path $rutaConfiguracion)) {
        Write-Host "Error: Unable to write to the configuration file."
        exit
    } else {
        Write-Host "Content added to the configuration file successfully."
    }

} else {
    Write-Host "User not found in the loaded list."
}

I'm trying to do an automatation following these rules:

1: Identify current user into the pc 2: Verifiy if chocolatey is installed if not, install it. to after this, install linphone through chocolatey 3: Verify and catch the current email linked with Onedrive into the pc, to match this email later into a CSV, and other properties to the user to complete the authentication id and password charged into a csv file. 4: Add the content to the configuration file, with the varible that I've asigned into the script

0

There are 0 answers