ipphone.psm1

<#
    Copyright (c) 2018 Shane Hoey
 
    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 
    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#>


class ipphoneDevice {
    [string]$ipphone
    [ipaddress]$ipaddress
    [string]$macaddress
    [string]$serialnumber
    [pscredential]$ippCredential
    [pscredential]$sipCredential
    [string]$sipAddress
    [string]$RegisteredSipAddress
    
    ipphoneDevice ([string]$ipphone, [ipaddress]$ipaddress, [string]$macaddress, [string]$serialnumber, [pscredential]$ippCredential, [pscredential]$sipCredential, [string]$sipAddress, [string]$RegisteredSipAddress) 
    {
        $this.ipphone         =  $ipphone
        $this.macaddress      =  $macaddress
        $this.serialnumber    =  $serialnumber
        $this.ippCredential   =  $ippCredential
        $this.sipCredential   =  $sipCredential
        $this.sipAddress      =  $sipAddress
        $this.RegisteredSipAddress = $RegisteredSipAddress
    }

    ipphoneDevice ([string]$ipphone) 
    {
      $this.ipphone     = $ipphone
    }

    ipphoneDevice () {}

  }
 
  #Force TLS 1.2 on windows powershell current session only
  if ($PSEdition -ne "Core") {[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12}

#Usage Statistics please refer to https://docs.shanehoey.com/terms
try{
    $body =  @{ "script"="ipphone";} | ConvertTo-Json
    Invoke-RestMethod -uri "https://api.shanehoey.com/scripts/" -Method put -body $body -ContentType "application/json" -ErrorAction SilentlyContinue | out-null
} 
catch{ }

Write-Verbose -Message "The 'ipphone PowerShell Module' is still experimental." -Verbose
Write-Verbose -Message "If you encounter an issue using ipphone PowerShell Module please review or create an issue at" -verbose
Write-Verbose -Message "https://github.com/shanehoey/ipphones/issues" -Verbose

function Set-ipphoneTrustAllCertPolicy 
{
    [CmdletBinding(SupportsShouldProcess = $true,  ConfirmImpact = 'High' )]
    param()
    
    #Exist when core detected
    if ($PSEdition -eq "Core")
    {
        Write-Warning "PowerShell Core should only use the -SkipCertificateCheck Parameter" -WarningAction Continue
    }
    else
    {   
        if (([System.Net.ServicePointManager]::SecurityProtocol).tostring() -notlike "*Tls12*" ) 
        {
            Write-Warning "Set TLS1.2 as default Security Protocol to current shell"  -WarningAction Continue
            [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Tls12'
            $settls = $true
        }
        
        if (([System.Net.ServicePointManager]::CertificatePolicy).GetType().name -eq "DefaultCertPolicy") 
        { 
            Write-Warning "Added TrustAllCertsPolicy to current shell"  -WarningAction Continue
            Add-Type -TypeDefinition @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
    public bool CheckValidationResult(
        ServicePoint srvPoint, X509Certificate certificate,
        WebRequest request, int certificateProblem) {
        return true;
    }
}
"@

            [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
            $setcert = $true
           
        }

        if ($settls -or $setcert) { Write-Warning "Exit PowerShell to revert these changes" -WarningAction Continue }
    
    }
}


function Test-ipphoneICMP
{
    [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'medium')]
    param(

        [Parameter(Mandatory = $true,    ParameterSetName = 'default' )]
        [string]$ipphone
    )
      
    try 
    {
        test-connection -ComputerName $ipphone -Count 1 -Quiet
    }
    catch 
    {
        $false
    }

}


function Test-ipphoneWeb
{
    [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'medium')]
    param(

        [Parameter(Mandatory = $true,    ParameterSetName = 'default' )]
        [string]$ipphone
    )
      
    try 
    {
        $result = Invoke-WebRequest -uri "http://$ipphone/" -UseBasicParsing
        if ($result.content -like "*mainform.cgi?go=mainframe.htm*") { $true } 
        else 
        {$false}
    }
    catch 
    {
        $false
    }

}


function Test-ipphoneTrustCertPolicy 
{
    [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'medium')]
    param(

        [Parameter(Mandatory = $true,    ParameterSetName = 'default' )]
        [string]$ipphone
    )
      
    try 
    {
        $result = Invoke-WebRequest -uri "https://$ipphone/" -UseBasicParsing 
        if ($result.statuscode -eq "200") {$true} else {$false}
    }
    catch 
    {
        $false
    }

}


Function Invoke-ipphoneWebRequest 
{
    [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'medium')]
    param(

        [Parameter(Mandatory = $true,    ParameterSetName='default')]
        [string]$ipphone,
            
        [Parameter(Mandatory = $true,    ParameterSetName='default')]
        [string]$action,

        [Parameter(Mandatory = $false,    ParameterSetName='default')]
        [ValidateSet('Get', 'Put','Post','Delete')]
        [string]$method = "Get",

        [Parameter(Mandatory = $false,    ParameterSetName='default')]
        [Microsoft.PowerShell.Commands.WebRequestSession]$websession,

        [Parameter(Mandatory = $false,    ParameterSetName='default')]
        $body,
    
        [Parameter(Mandatory = $false,    ParameterSetName='default')]
        [string]$ContentType,

        [Parameter(Mandatory = $false,    ParameterSetName='default')]
        [switch]$returnobject,
        
        [Parameter(Mandatory = $false,    ParameterSetName='default')]
        [ValidateSet('http', 'https')]
        [string]$http = "https",

        [Parameter(Mandatory = $false,    ParameterSetName='default')]
        [switch]$SkipCertificateCheck
    )
    
    Process 
    { 
        try 
        {       
            $Parameters = @{ }
            $Parameters.Uri = "$($http)://$($ipphone)$($Action)"
            $Parameters.Method = $Method 
            if ($PSBoundParameters.WebSession -is [Microsoft.PowerShell.Commands.WebRequestSession])
            {
                $Parameters.WebSession = $WebSession
            }
            else  
            {
                $Parameters.SessionVariable = "WebSession"
            } 
            if ($PSBoundParameters.body) 
            {
                $Parameters.Body = $Body
            }
            if ($PSBoundParameters.ContentType)
            {
                $Parameters.ContentType  = $ContentType
            }
       

            if ($psboundparameters.SkipCertificateCheck) 
            { 
                Switch ($PSEdition)
                {
                    "Desktop"
                    {   
                        Write-Verbose "PSEdition Desktop"
                        if (!(test-ipphonetrustcertpolicy)) { write-warning "As a workaround to SSL cert run set-ipphonetrustallcertpolicy before continuing" -WarningAction Stop }  

                        $result = Invoke-WebRequest @parameters -useragent "ipphone PowerShell/$($psversiontable.psedition)/$($psversiontable.psversion)" -ErrorAction Stop 
                        $script:ippWebSession = $websession
                    }
                    "Core"
                    {
                        Write-Verbose "PSEdition Core"
                        $result = Invoke-WebRequest @parameters -useragent "ipphone PowerShell/$($psversiontable.psedition)/$($psversiontable.psversion)" -skipcertificatecheck -ErrorAction Stop 
                        $script:ippWebSession = $websession
                    }
                }
            }
            else 
            {
                $result = Invoke-WebRequest @parameters -ErrorAction Stop 
                $script:ippWebSession = $websession
            }
        
            if ($PSBoundParameters.returnobject) 
            {
                $result
            }
        
        }
        catch [System.Net.WebException]
        {
            if ($psitem.exception.message -eq "The underlying connection was closed: An unexpected error occurred on a send.")
            {
                Write-warning "[Error] - try re-running the last with -skipcertificatecheck parameter or Set-ipphoneTrustAllCertPolicy"
            }
        }
        catch 
        {
            Write-Warning -Message "[Error] - $_.Exception"
        }
    }
}
  
Function Get-ipphoneWebSession 
{

    [CmdletBinding(ConfirmImpact = 'low')]

    param()
    Process 
    { 
        $ippWebSession
    }
  }

function new-ipphonewebsession
{

    [CmdletBinding( ConfirmImpact = 'medium', DefaultParameterSetName = "default" )]
    param(

        [Parameter( Mandatory = $true, ParameterSetName = 'default' )]
        [string]$ipphone,
            
        [Parameter( Mandatory = $false, ParameterSetName = 'default' )]
        [switch]$returnobject,

        [Parameter(Mandatory = $false,    ParameterSetName='default')]
        [switch]$SkipCertificateCheck

    )

    process 
    { 
        try 
        {  

            $parameters = @{}
            $parameters.ipphone = $ipphone
            $parameters.action = "/"
            if ($PSBoundParameters.SkipCertificateCheck)
            {
                    $parameters.SkipCertificateCheck = $true
            }

            $result = invoke-ipphoneWebRequest @parameters -returnobject

            if ($result.statuscode -eq 200) 
            { 
                if ($result.rawcontent -like "*URL=mainform.cgi?go=mainframe.htm*") 
                {
                    $ippWebSession
                }
                else 
                {
                    throw
                }
            }
            else 
            {
                throw 
            } 

        }
        catch 
        {
            if(!(test-ipphoneTrustCertPolicy -ipphone $ipphone)){throw 'SSL Trust Certificate Policy'}
        }
    }
}


function Test-ipphoneConnection
{

    [CmdletBinding(ConfirmImpact = 'low',DefaultParameterSetName="default")]
    param(
  
        [Parameter(Mandatory = $true,    ParameterSetName='default')]
        [string]$ipphone,

        [Parameter(Mandatory = $true,    ParameterSetName='default')]
        [Microsoft.PowerShell.Commands.WebRequestSession]$websession

    )

    process 
    { 
            $Parameters = @{ }
            $Parameters.ipphone = $ipphone
            $Parameters.action = "/login.cgi"
            $Parameters.WebSession = $WebSession
                       
            $result = Invoke-ipphoneWebRequest @parameters -returnobject

            if ($result.content -like "*/mainform.cgi?go=mainframe.htm*") { $true } 
            elseif ($result.content -like "*Web Login*") { $false }
            elseif ($result.content -like "*Login failed*") { $false }
            else { $false }

        
    }

}

function Connect-ipphone
{

    [CmdletBinding(ConfirmImpact = 'low',DefaultParameterSetName="credential")]
    param(
  
        [Parameter(Mandatory = $true,    ParameterSetName='credential')]
        [Parameter(Mandatory = $true,    ParameterSetName='securestring')]
        [Parameter(Mandatory = $true,    ParameterSetName='string')]
        [string]$ipphone,
            
        [Parameter(Mandatory = $true,    ParameterSetName='securestring')]
        [Parameter(Mandatory = $true,    ParameterSetName='string')]
        [string]$username,

        [Parameter(Mandatory = $true,    ParameterSetName='securestring')]
        [securestring]$password,

        [Parameter(Mandatory = $true,    ParameterSetName='string')]
        [string]$passwordtext,

        [Parameter(Mandatory = $true,    ParameterSetName='credential')]
        [pscredential]$credential,

        [Parameter(Mandatory = $true,    ParameterSetName='credential')]
        [Parameter(Mandatory = $true,    ParameterSetName='securestring')]
        [Parameter(Mandatory = $true,    ParameterSetName='string')]
        [Microsoft.PowerShell.Commands.WebRequestSession]$websession,

        [Parameter(Mandatory = $false,    ParameterSetName='credential')]
        [Parameter(Mandatory = $false,    ParameterSetName='securestring')]
        [Parameter(Mandatory = $false,    ParameterSetName='string')]
        [switch]$returnobject,

        [Parameter(Mandatory = $false,    ParameterSetName='default')]
        [switch]$SkipCertificateCheck

    )



    process 
    { 

            $Parameters = @{ }
            $Parameters.ipphone = $ipphone
            $Parameters.action = "/login.cgi"
            $Parameters.Method ="post"
            $parameters.ContentType = "application/x-www-form-urlencoded" 
            if ($PSBoundParameters.password)     { $credential = New-Object System.Management.Automation.PSCredential ($username, $password) }
            if ($PSBoundParameters.passwordtext) { $credential = New-Object System.Management.Automation.PSCredential ($username, (ConvertTo-SecureString $passwordtext -AsPlainText -Force)) }
            $parameters.body = @{user="$($credential.username)";psw="$([Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($credential.GetNetworkCredential().password)))" } 
            if ($PSBoundParameters.WebSession -is [Microsoft.PowerShell.Commands.WebRequestSession])
            {
                $Parameters.WebSession = $WebSession
            }
            if ($PSBoundParameters.SkipCertificateCheck)
            {
                    $parameters.SkipCertificateCheck = $true
            }

            $result = Invoke-ipphoneWebRequest @parameters -returnobject

            if ($result.content -like "*Login failed*") { write-warning "Incorrect username or password"  }

            if($PSBoundParameters.returnobject) 
            {    
                $result 
            }
        
    }

  }

function Invoke-ipphoneReboot
{

    [CmdletBinding(ConfirmImpact = 'low',DefaultParameterSetName="default")]
    param(
  
        [Parameter(Mandatory = $true,    ParameterSetName='default')]
        [string]$ipphone,

        [Parameter(Mandatory = $true,    ParameterSetName='default')]
        [Microsoft.PowerShell.Commands.WebRequestSession]$websession
    )

    process 
    { 

        $Parameters = @{ }
        $Parameters.ipphone = $ipphone
        $Parameters.action = "/mainform.cgi/reboot.htm"
        $Parameters.Method ="post"
        $parameters.body = @{ REBOOT = 2 }
        $parameters.contenttype = "application/x-www-form-urlencoded" 
        $parameters.webSession = $websession 

        $result = Invoke-ipphoneWebRequest @parameters -returnobject

        if($PSBoundParameters.returnobject) 
            {    
                $result 
            }
        
    }

  }


function Invoke-ipphoneReset
{

    [CmdletBinding(ConfirmImpact = 'low',DefaultParameterSetName="default")]
    param(
  
        [Parameter(Mandatory = $true,    ParameterSetName='default')]
        [string]$ipphone,
            
        [Parameter(Mandatory = $true,    ParameterSetName='default')]
        [Microsoft.PowerShell.Commands.WebRequestSession]$websession
    )

    process 
    { 

        $Parameters = @{ }
        $Parameters.ipphone = $ipphone
        $Parameters.action = "/mainform.cgi/reset.htm"
        $Parameters.Method ="post"
        $parameters.body = @{ CONFIG = 2 }
        $parameters.contenttype = "application/x-www-form-urlencoded" 
        $parameters.webSession = $websession 

        $result = Invoke-ipphoneWebRequest @parameters -returnobject

        if($PSBoundParameters.returnobject) 
            {    
                $result 
            }
        
    }

  }

function Get-ipphoneMacAddress
{

    [CmdletBinding(ConfirmImpact = 'low',DefaultParameterSetName="default")]
    param(
  
        [Parameter(Mandatory = $true,    ParameterSetName='default')]
        [string]$ipphone,
            
        [Parameter(Mandatory = $true,    ParameterSetName='default')]
        [Microsoft.PowerShell.Commands.WebRequestSession]$websession
    )

    process 
    { 

        $Parameters = @{ }
        $Parameters.ipphone = $ipphone
        $Parameters.action = "/mainform.cgi/network_status.htm"
        $parameters.webSession = $websession 

        $result = Invoke-ipphoneWebRequest @parameters -returnobject
        if ($result.statuscode -eq 200) {
            $macaddress = [Regex]::new('([0-9A-F]{2}[:-]){5}([0-9A-F]{2})')
            $matches = $macaddress.Matches($result)
            $matches.Value.replace('-','').replace(':','')
        }
        
    }

  }

  function Get-ipphoneStatus
  {
  
      [CmdletBinding(ConfirmImpact = 'low',DefaultParameterSetName="default")]
      param(
    
          [Parameter(Mandatory = $true,    ParameterSetName='default')]
          [string]$ipphone,
              
          [Parameter(Mandatory = $true,    ParameterSetName='default')]
          [Microsoft.PowerShell.Commands.WebRequestSession]$websession
      )
  
      process 
      { 
  
          $Parameters = @{ }
          $Parameters.ipphone = $ipphone
          $Parameters.action = "/voip_status.cgi"
          $parameters.webSession = $websession 
  
          $result = Invoke-ipphoneWebRequest @parameters -returnobject
          if ($result.statuscode -eq 200) {
            ([xml]$result.content).status | select-object -ExpandProperty line
          }
          
      }
  
    }
    function Get-ipphoneHookStatus
    {
    
        [CmdletBinding(ConfirmImpact = 'low',DefaultParameterSetName="default")]
        param(
      
            [Parameter(Mandatory = $true,    ParameterSetName='default')]
            [string]$ipphone,
                
            [Parameter(Mandatory = $true,    ParameterSetName='default')]
            [Microsoft.PowerShell.Commands.WebRequestSession]$websession
        )
    
        process 
        { 
    
            $Parameters = @{ }
            $Parameters.ipphone = $ipphone
            $Parameters.action = "/voip_status.cgi"
            $parameters.webSession = $websession
    
            $result = Invoke-ipphoneWebRequest @parameters -returnobject
            if ($result.statuscode -eq 200) {
               ([xml]$result.content).status | select-object AudioDevice, HookState

            }
            
        }
    
      }

function Test-ipphoneMacAddress
{

    [CmdletBinding(ConfirmImpact = 'low',DefaultParameterSetName="default")]
    param(
  
        [Parameter(Mandatory = $true,    ParameterSetName='default')]
        [string]$ipphone,

        [Parameter(Mandatory = $true,    ParameterSetName='default')]
        [ValidatePattern('([0-9A-F]{2}[:-]?){5}([0-9A-F]){2}')]
        [string]$macaddress,
            
        [Parameter(Mandatory = $true,    ParameterSetName='default')]
        [Microsoft.PowerShell.Commands.WebRequestSession]$websession
    )

    process 
    { 

        $Parameters = @{ }
        $Parameters.ipphone = $ipphone
        $Parameters.action = "/mainform.cgi/network_status.htm"

        $macaddress = $macaddress.replace('-','').replace(':','')
        $ippphonemacaddress = get-ipphonemacaddress -ipphone $ipphone -websession $websession

        if($macaddress -eq $ippphonemacaddress) {$true} else {$false}
        
    }

  }

function Invoke-ipphoneLoginUser
{

    [CmdletBinding(ConfirmImpact = 'low',DefaultParameterSetName="default")]
    param(
  
        [Parameter(Mandatory = $true,    ParameterSetName='default')]
        [Parameter(Mandatory = $true,    ParameterSetName='cloud')]
        [Parameter(Mandatory = $true,    ParameterSetName='logoff')]
        [string]$ipphone,
            
        [Parameter(Mandatory = $true,    ParameterSetName='default')]
        [string]$sipaddress,

        [Parameter(Mandatory = $true,    ParameterSetName='default')]
        [pscredential]$sipcredential,

        [Parameter(Mandatory = $true,    ParameterSetName='default')]
        [Parameter(Mandatory = $true,    ParameterSetName='cloud')]
        [Parameter(Mandatory = $true,    ParameterSetName='logoff')]
        [Microsoft.PowerShell.Commands.WebRequestSession]$websession,

        [Parameter(Mandatory = $false,    ParameterSetName='logoff')]
        [switch]$Logoffuser,

        [Parameter(Mandatory = $false,    ParameterSetName='cloud')]
        [switch]$cloud,

        [Parameter(Mandatory = $false,    ParameterSetName='default')]
        [Parameter(Mandatory = $false,    ParameterSetName='cloud')]
        [Parameter(Mandatory = $false,    ParameterSetName='logoff')]
        [switch]$returnobject

    )

    process 
    { 

        $Parameters = @{ }
        $Parameters.ipphone = $ipphone
        $Parameters.action = "/mainform.cgi/SfB_signin.htm"
        $Parameters.Method ="post"
        if ($PsCmdlet.ParameterSetName -eq 'default') 
        {
            $parameters.body = @{SIGNINMODE="1";LYNC_SIGNIN_ADDR="$($sipaddress)";LYNC_USER_NAME="$($sipcredential.username)";LYNC_PASSWORD="$($sipcredential.GetNetworkCredential().password)";}
        }
        elseif ($PsCmdlet.ParameterSetName -eq 'cloud') 
        {
            $parameters.body = @{ SIGNINMODE = "2";}
            write-warning "use get-ipphonestatus to retrieve the code" -WarningAction Continue
        }
        elseif ($PsCmdlet.ParameterSetName -eq 'logoff') 
        {
            $parameters.body = @{LYNC_SIGN_OUT="2";}
        }
        $parameters.contenttype = "application/x-www-form-urlencoded" 
        $parameters.webSession = $websession 

        $result = Invoke-ipphoneWebRequest @parameters -returnobject

        if($PSBoundParameters.returnobject) 
            {    
                $result 
            }
        
    }

  }

  function set-ipphoneProvisioning
  {
  
      [CmdletBinding(ConfirmImpact = 'low',DefaultParameterSetName="dhcp")]
      param(
    
          [Parameter(Mandatory = $true,    ParameterSetName='dhcp')]
          [Parameter(Mandatory = $true,    ParameterSetName='disable')]
          [Parameter(Mandatory = $true,    ParameterSetName='static')]
          [Parameter(Mandatory = $true,    ParameterSetName='sfb')]
          [string]$ipphone,
              

          [Parameter(Mandatory = $true,    ParameterSetName='dhcp')]
          [Parameter(Mandatory = $true,    ParameterSetName='disable')]
          [Parameter(Mandatory = $true,    ParameterSetName='static')]
          [Parameter(Mandatory = $true,    ParameterSetName='sfb')]
          [Microsoft.PowerShell.Commands.WebRequestSession]$websession,
  
          [Parameter(Mandatory = $false,    ParameterSetName='dhcp')]
          [Parameter(Mandatory = $false,    ParameterSetName='disable')]
          [Parameter(Mandatory = $false,    ParameterSetName='static')]
          [Parameter(Mandatory = $false,    ParameterSetName='sfb')]
          [switch]$returnobject
  
      )
      #ASU_METHOD=0&
      SFB_UP_SERVER=0
      FW_URL=https%3A%2F%2Fippmgr.shanehoey.com%2Ffirmwarefiles%2F
      NOW_FW=0
      CFG_URL=https%3A%2F%2Fippmgr.shanehoey.com%2Fipp%2Fdhcpoption160.cfg
      NOW_CFG=0
      FW_DYN=0
      CFG_DYN=0
      OPTVAL=160
      ASU_PERIOD=0
      ASU_HOURS=1
      ASU_EDTIME=0
      ASU_EDWDAY=0
      ASU_EDWTIME=0
      ASU_RANDOM=120
      SFB_ASU_METHOD=0
      SFB_CFG_DYN=0
      SFB_CFG_URL=https%3A%2F%2Fippmgr.shanehoey.com%2Fipp%2Fdhcpoption160.cfg
      SFB_NOW_CFG=0
      SFB_OPTVAL=160
      SFB_ASU_PERIOD=0
      SFB_ASU_HOURS=1
      SFB_ASU_EDTIME=0
      SFB_ASU_EDWDAY=0
      SFB_ASU_EDWTIME=0
      SFB_ASU_RANDOM=120
      
      process 
      { 
  
          $Parameters = @{ }
          $Parameters.ipphone = $ipphone
          $Parameters.action = "/mainform.cgi/auto_provision.htm"
          $Parameters.Method ="post"
          if ($PsCmdlet.ParameterSetName -eq 'dhcp') 
          {
              $parameters.body = @{ASU_METHOD="1";}
          }
          elseif ($PsCmdlet.ParameterSetName -eq 'disable') 
          {
              $parameters.body = @{ASU_METHOD="0";}
          }
          elseif ($PsCmdlet.ParameterSetName -eq 'static') 
          {
              $parameters.body = @{ASU_METHOD="2";}
          }
          elseif ($PsCmdlet.ParameterSetName -eq 'sfb') 
          {
              $parameters.body = @{ASU_METHOD="3";}
          }
          $parameters.contenttype = "application/x-www-form-urlencoded" 
          $parameters.webSession = $websession 
  
          $result = Invoke-ipphoneWebRequest @parameters -returnobject
  
          if($PSBoundParameters.returnobject) 
              {    
                  $result 
              }
          
      }
  
    }
# SIG # Begin signature block
# MIINCgYJKoZIhvcNAQcCoIIM+zCCDPcCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUDG1IYu2VMomi/KqlAyr8Icv9
# HNmgggpMMIIFFDCCA/ygAwIBAgIQDq/cAHxKXBt+xmIx8FoOkTANBgkqhkiG9w0B
# AQsFADByMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYD
# VQQLExB3d3cuZGlnaWNlcnQuY29tMTEwLwYDVQQDEyhEaWdpQ2VydCBTSEEyIEFz
# c3VyZWQgSUQgQ29kZSBTaWduaW5nIENBMB4XDTE4MDEwMzAwMDAwMFoXDTE5MDEw
# ODEyMDAwMFowUTELMAkGA1UEBhMCQVUxGDAWBgNVBAcTD1JvY2hlZGFsZSBTb3V0
# aDETMBEGA1UEChMKU2hhbmUgSG9leTETMBEGA1UE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