Private/Set-MSGObject.ps1

function Set-MSGObject {
    [CmdletBinding(SupportsShouldProcess, ConfirmImpact='Medium')]
    param (
        # Parameter help description
        [Parameter(Mandatory = $true)][string] $uri,
        [Parameter(Mandatory = $false)][hashtable] $body,
        [switch] $raw,
        [switch] $Force,
        [switch] $PassThru
    )
    
    begin {
        $method = "patch"

        if (-not $PSBoundParameters.ContainsKey('Verbose')) {
            $VerbosePreference = $PSCmdlet.SessionState.PSVariable.GetValue('VerbosePreference')
        }
        if (-not $PSBoundParameters.ContainsKey('Confirm')) {
            $ConfirmPreference = $PSCmdlet.SessionState.PSVariable.GetValue('ConfirmPreference')
        }
        if (-not $PSBoundParameters.ContainsKey('WhatIf')) {
            $WhatIfPreference = $PSCmdlet.SessionState.PSVariable.GetValue('WhatIfPreference')
        }
    }
    
    
    process {
        $bodyString =  if($raw){$body}else{ConvertTo-Json -InputObject $body -Compress} 
        if ($Force -or $PSCmdlet.ShouldProcess("$uri")) {
            $retval = Invoke-MSGWebRequest -method $method -uri $uri -body $bodyString -Force:$Force
        }
        if($PassThru){
            $retval = return Invoke-MSGWebRequest -method "get" -uri $uri -Force:$Force
        }
        return $retval
    }
}