CoreOps/Chap/Remove-SDPHostChapUser.ps1

<#
    .SYNOPSIS
    Removes a CHAP user from a host.

    .DESCRIPTION
    Clears the CHAP user assignment on an existing host. Accepts piped
    input from Get-SDPHost.

    .PARAMETER hostName
    The host name to clear the CHAP user from. Accepts pipeline input by
    property name.

    .PARAMETER context
    K2 context to use for authentication. Defaults to 'sdpconnection'.

    .EXAMPLE
    Remove-SDPHostChapUser -hostName Host01

    .EXAMPLE
    Get-SDPHost -name Host01 | Remove-SDPHostChapUser

    .NOTES
    Authored by J.R. Phillips (GitHub: JayAreP)

    .LINK
    https://github.com/silk-us/silk-sdp-powershell-sdk
#>


function Remove-SDPHostChapUser {
    [CmdletBinding(SupportsShouldProcess, ConfirmImpact='High')]
    param(
        [parameter(ValueFromPipelineByPropertyName, Mandatory)]
        [Alias('pipeName')]
        [string] $hostName,
        [parameter()]
        [switch] $Force,
        [parameter()]
        [string] $context = "sdpconnection"
    )

    begin {
        $endpoint = 'hosts'
    }

    process {

        # Special Ops — resolve the host.

        $hostObj = Get-SDPHost -name $hostName -context $context -doNotResolve

        # Build the request body

        $body = New-Object psobject
        $body | Add-Member -MemberType NoteProperty -Name "map_auth_profiles_names" -Value $null

        # Call

        if ($Force -and -not $PSBoundParameters.ContainsKey('Confirm')) {
            $ConfirmPreference = 'None'
        }
        if ($PSCmdlet.ShouldProcess("SDPHost hostName=$hostName CHAP user", 'Remove')) {
            $results = Invoke-SDPRestCall -endpoint "$endpoint/$($hostObj.id)" -method PATCH -body $body -context $context
            return $results
        }
    }
}