poshbox.psm1

<#
    .NOTES
    --------------------------------------------------------------------------------
     Code generated by: SAPIEN Technologies, Inc., PowerShell Studio 2019 v5.6.165
     Generated on: 6/22/2019 11:53 AM
     Generated by: whiggs
    --------------------------------------------------------------------------------
    .DESCRIPTION
        Script generated by PowerShell Studio 2019
#>



    <#
        ===========================================================================
         Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.155
         Created on: 11/18/2018 11:55 AM
         Created by: whiggs
         Organization:
         Filename: poshbox.psm1
        -------------------------------------------------------------------------
         Module Name: poshbox
        ===========================================================================
    #>

    
    #.EXTERNALHELP en-US\poshbox-help.xml

function connect-box
{
    [CmdletBinding(DefaultParameterSetName = 'reg')]
    param
    (
        [Parameter(ParameterSetName = 'file', Mandatory = $true)]
        [ValidateScript({ Test-Path $_ -PathType Leaf })]
        [String]$path,
        [ValidatePattern("\d{4,}")]
        [string]$id
    )
    
    If ($IsWindows -eq $true)
    {
        If ($PSCmdlet.ParameterSetName -like "file")
        {
            If (Test-Path "HKCU:\Software\boxmodule")
            {
                Remove-Item "HKCU:\Software\boxmodule" -Force
            }
            New-Item "HKCU:\Software\boxmodule" -Force
            $json = Get-Content $path | ConvertFrom-Json
            Set-ItemProperty -Path "HKCU:\Software\boxmodule" -Name "enterpriseid" -Value $json.enterpriseID -Force
            Set-ItemProperty -Path "HKCU:\Software\boxmodule" -Name "clientid" -Value $json.boxAppSettings.clientID -Force
            Set-ItemProperty -Path "HKCU:\Software\boxmodule" -Name "clientsecret" -Value $json.boxAppSettings.clientSecret -Force
            Set-ItemProperty -Path "HKCU:\Software\boxmodule" -Name "passphrase" -Value $json.boxAppSettings.appAuth.passphrase -Force
            Set-ItemProperty -Path "HKCU:\Software\boxmodule" -Name "privatekey" -Value $json.boxAppSettings.appAuth.privateKey -Force
            Set-ItemProperty -Path "HKCU:\Software\boxmodule" -Name "publickeyid" -Value $json.boxAppSettings.appAuth.publicKeyID -Force
        }
        
        Try
        {
            $boxob = Get-ItemProperty -Path "HKCU:\Software\boxmodule" -ErrorAction Stop
        }
        Catch
        {
            throw "The box authentication values have not been saved. Run this command again and provide the path to the json file with the authentication information. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
        }
        If (($boxob.psobject.Properties.name -notcontains "enterpriseid") -or ($boxob.psobject.Properties.name -notcontains "clientid") -or ($boxob.psobject.Properties.name -notcontains "clientSecret") -or ($boxob.psobject.Properties.name -notcontains "passphrase") -or ($boxob.psobject.Properties.name -notcontains "privatekey") -or ($boxob.psobject.Properties.name -notcontains "publickeyid"))
        {
            throw "Box authentication values are missing. Run this command again and provide the path to the json file with the authentication information. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
        }
        $boxconfig = New-Object -TypeName Box.v2.Config.Boxconfig -Argumentlist $boxob.clientid, $boxob.clientsecret, $boxob.enterpriseid, $boxob.privatekey, $boxob.passphrase, $boxob.publickeyid
    }
    Else
    {
        If ($PSCmdlet.ParameterSetName -like "file")
        {
            If (!(Test-Path $HOME/.box))
            {
                New-Item $HOME/.box -ItemType directory -force
            }
            If (Test-Path $HOME/.box/settings.json)
            {
                Remove-Item $HOME/.box/settings.json -force
            }
            Move-Item -Path $path -Destination $HOME/.box/settings.json -force
        }
        $json = Get-Content $HOME/.box/settings.json | convertfrom-json
        $boxconfig = New-Object -TypeName Box.v2.Config.Boxconfig -Argumentlist $json.boxAppSettings.clientID, $json.boxAppSettings.clientSecret, $json.enterpriseID, $json.boxAppSettings.appAuth.privateKey, $json.boxAppSettings.appAuth.passphrase, $json.boxAppSettings.appAuth.publicKeyID
    }
    $boxJWT = New-Object -TypeName Box.V2.JWTAuth.BoxJWTAuth -Argumentlist $boxconfig
    $tokenreal = $boxJWT.AdminToken
    If (-not $id)
    {
        $global:adminclient = $boxjwt.AdminClient($tokenreal)
    }
    Else
    {
        $global:adminclient = $boxjwt.AdminClient($tokenreal, $id)
    }
    If ($adminclient -eq $null)
    {
        Write-error "The box client was not created successfully. This could have been caused by invalid authentication values. Try running this command again and provide the path to the json file with the authentication information. Also ensure that the box app from which you obtained the authentication information has been registered in your enterprise settings. For more information on these topics, please read the instructions at https://github.com/whiggs/PoshBox. Submit an issue in the repo if it still does not work."
        return
    }
    
    #return $global:adminclient
}
function get-boxusers
    {
        [CmdletBinding(DefaultParameterSetName = "autopage")]
        param
        (
            [string]$SearchString = $null,
            [Parameter(ParameterSetName = "noautopage")]
            [ValidateRange(1, 1000)]
            [int]$limit = 1000,
            [Parameter(ParameterSetName = "noautopage")]
            [int]$offset = 0,
            [String[]]$fields = $null,
            [String]$usertype = $null,
            [String]$externalappuserid = $null,
            [Parameter(ParameterSetName = 'autopage')]
            [Switch]$autopaginate
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        If ($PSCmdlet.ParameterSetName -like "autopage")
        {
            $usertask = $adminclient.UsersManager.GetEnterpriseUsersAsync($SearchString, $offset, $limit, $fields, $usertype, $externalappuserid, $true)
        }
        Else
        {
            $usertask = $adminclient.UsersManager.GetEnterpriseUsersAsync($SearchString, $offset, $limit, $fields, $usertype, $externalappuserid, $false)
        }
        $usertask.Wait()
        If ($usertask.IsFaulted -eq $true)
        {
            Write-error $usertask.Exception.InnerException
            return
        }
        else
        {
            return $usertask.Result
        }
    }
    function set-boxuserlogin
    {
        param
        (
            [parameter(Mandatory = $true)]
            [System.String]$id,
            [parameter(Mandatory = $true)]
            [string]$newlogin,
            [String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $change = $adminclient.UsersManager.ChangeUsersLoginAsync($id, $newlogin, $fields)
        $change.wait()
        If ($change.IsFaulted -eq $true)
        {
            Write-Error $change.Exception.InnerException
            return
        }
        Else
        {
            return $change.Result
        }
    }
    function new-boxuser
    {
        param
        (
            [parameter(Mandatory = $true)]
            [hashtable]$userdetails,
            [String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        If (($userdetails.Keys -notcontains "name") -and ($userdetails.Keys -notcontains "login"))
        {
            Write-Error "The hashtable does not define the `"name`" or `"login`" keys. These must be present to create the new user."
            return
        }
        Else
        {
            $userrequest = New-Object Box.V2.Models.BoxUserRequest -Property $userdetails
            $newuser = $adminclient.UsersManager.CreateEnterpriseUserAsync($userrequest, $fields)
            
            $newuser.Wait()
            If ($newuser.IsFaulted -eq $true)
            {
                Write-error $newuser.Exception.InnerException
                return
            }
            Else
            {
                return $newuser.Result
            }
        }
    }
    
    function new-boxemailalias
    {
        [CmdletBinding()]
        param (
            [Parameter(Mandatory = $true)]
            [String]$id,
            [Parameter(Mandatory = $true)]
            [String]$emailalias
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $emailaliasproc = $adminclient.UsersManager.AddEmailAliasAsync($id, $emailalias)
        $emailaliasproc.Wait()
        If ($emailaliasproc.IsFaulted -eq $true)
        {
            Write-error $emailaliasproc.Exception.InnerException
            return
        }
        Else
        {
            return $emailaliasproc.Result
        }
    }
    function remove-boxuser
    {
        [CmdletBinding()]
        param (
            [Parameter(Mandatory = $true)]
            [String]$id,
            [Switch]$notify,
            [Switch]$force
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        If ($notify)
        {
            If ($force)
            {
                $delete = $adminclient.UsersManager.DeleteEnterpriseUserAsync($id, $true, $true)
            }
            Else
            {
                $delete = $adminclient.UsersManager.DeleteEnterpriseUserAsync($id, $true, $false)
            }
        }
        Else
        {
            If ($force)
            {
                $delete = $adminclient.UsersManager.DeleteEnterpriseUserAsync($id, $false, $true)
            }
            Else
            {
                $delete = $adminclient.UsersManager.DeleteEnterpriseUserAsync($id, $false, $false)
            }
        }
        $delete.Wait()
        If ($delete.IsFaulted -eq $true)
        {
            Write-Error $delete.Exception.InnerException
            return
        }
        Else
        {
            return $delete.Result
        }
        
    }
    
    function transfer-boxusercontent
    {
        [CmdletBinding()]
        param (
            [Parameter(Mandatory = $true)]
            [String]$id,
            [Parameter(Mandatory = $true)]
            [String]$ownerid,
            [Switch]$notify
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        If ($notify)
        {
            $transfer = $adminclient.UsersManager.MoveUserFolderAsync($id, $ownerid, "0", $true)
        }
        Else
        {
            $transfer = $adminclient.UsersManager.MoveUserFolderAsync($id, $ownerid, "0", $false)
        }
        $transfer.Wait()
        If ($transfer.IsFaulted -eq $true)
        {
            $transfer.Exception.InnerException
        }
        Else
        {
            $transfer.Result
        }
    }
    
    function upload-boxfile
    {
        [CmdletBinding()]
        param (
            [Parameter(Mandatory = $true)]
            [String]$filename,
            [Parameter(Mandatory = $true)]
            [String]$parentdirid,
            [Parameter(Mandatory = $true)]
            [String]$path,
            [String[]]$fields = $null,
            [Parameter(Mandatory = $true)]
            [system.TimeSpan]$timespan
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        If (!(Test-Path $path))
        {
            Write-Error "The file path you provided does not exist."
            Return
        }
        $file = [System.IO.File]::OpenRead($path)
        $request = @{
            name = "$filename"
            parent = @{
                id = "$parentdirid"
            }
        }
        $upload = $adminclient.FilesManager.UploadAsync($request, $file, $fields, $timespan)
        $upload.Wait()
        If ($upload.IsFaulted -eq $true)
        {
            Write-error $upload.Exception.InnerException
            return
        }
        Else
        {
            return $upload.Result
        }
    }
    Function remove-boxemailalias
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$userid,
            [Parameter(Mandatory = $true)]
            [String]$aliasid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $removealias = $adminclient.UsersManager.DeleteEmailAliasAsync($userid, $aliasid)
        $removealias.Wait()
        If ($removealias.IsFaulted -eq $true)
        {
            Write-error $removealias.Exception.InnerException
            return
        }
        Else
        {
            return $removealias.Result
        }
    }
    function Get-boxemailalias
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$userid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $getalias = $adminclient.UsersManager.GetEmailAliasesAsync($userid)
        $getalias.Wait()
        If ($getalias.IsFaulted -eq $true)
        {
            Write-error $getalias.Exception.InnerException
            return
        }
        Else
        {
            return $getalias.Result
        }
    }
    function Get-boxuserinfo
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$userid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $userinfo = $adminclient.UsersManager.GetUserInformationAsync($userid)
        $userinfo.Wait()
        If ($userinfo.IsFaulted -eq $true)
        {
            Write-error $userinfo.Exception.InnerException
            return
        }
        Else
        {
            return $userinfo.Result
        }
    }
    function invite-usertobox
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$exuseremail,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        Try
        {
            $boxob = Get-ItemProperty -Path "HKCU:\Software\boxmodule" -ErrorAction Stop
        }
        Catch
        {
            throw "Authentication information is missing from the environment. Please run `"connect-box`" to retrieve needed authentication info."
        }
        If (($boxob.psobject.Properties.name -notcontains "enterpriseid") -or ($boxob.psobject.Properties.name -notcontains "clientid") -or ($boxob.psobject.Properties.name -notcontains "clientSecret") -or ($boxob.psobject.Properties.name -notcontains "passphrase") -or ($boxob.psobject.Properties.name -notcontains "privatekey") -or ($boxob.psobject.Properties.name -notcontains "publickeyid"))
        {
            throw "Authentication information is missing from the environment. Please run `"connect-box`" to retrieve needed authentication info."
        }
        $act = New-Object Box.V2.Models.BoxActionableByRequest
        $act.Login = $exuseremail
        $req = New-Object Box.V2.Models.BoxRequestEntity
        $req.Id = (Get-ItemProperty "HKCU:\Software\boxmodule").enterpriseid
        $inviteob = New-Object Box.V2.Models.BoxUserInviteRequest
        $inviteob.ActionableBy = $act
        $inviteob.Enterprise = $req
        $invreq = $adminclient.UsersManager.InviteUserToEnterpriseAsync($inviteob, $fields)
        $invreq.Wait()
        If ($invreq.IsFaulted -eq $true)
        {
            Write-error $invreq.Exception.InnerException
            return
        }
        Else
        {
            return $invreq.Result
        }
        
    }
    
    function Get-boxuserinvite
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$inviteid,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $invitereq = $adminclient.UsersManager.GetUserInviteAsync($inviteid, $fields)
        $invitereq.Wait()
        If ($invitereq.IsFaulted -eq $true)
        {
            Write-error $invitereq.Exception.InnerException
            return
        }
        Else
        {
            return $invitereq.Result
        }
        
    }
    function set-boxuser
    {
        param (
            [Parameter(Mandatory = $true)]
            [hashtable]$updateinfo,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $boxuserreq = New-Object Box.V2.Models.BoxUserRequest -Property $updateinfo
        $userupdate = $adminclient.UsersManager.UpdateUserInformationAsync($boxuserreq, $fields)
        $userupdate.Wait()
        If ($userupdate.IsFaulted -eq $true)
        {
            Write-error $userupdate.Exception.InnerException
            return
        }
        Else
        {
            return $userupdate.Result
        }
    }
    
    function new-boxfolder
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$foldername,
            [Parameter(Mandatory = $true)]
            [String]$parentid,
            [string[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        #$folderreq = New-Object Box.V2.Models.BoxFolderRequest -Property $foldreq
        $folderreq = @{
            name = "$foldername"
            parent = @{
                id = "$parentid"
            }
        }
        $boxfolreq = $adminclient.FoldersManager.CreateAsync($folderreq, $fields)
        $boxfolreq.Wait()
        If ($boxfolreq.IsFaulted -eq $true)
        {
            Write-error $boxfolreq.Exception.InnerException
            return
        }
        Else
        {
            return $yu.Result
        }
        
    }
    function get-boxfolderitems
    {
        [CmdletBinding(DefaultParameterSetName = "auto")]
        param (
            [string]$folderid = "0",
            [Parameter(ParameterSetName = 'noauto')]
            [int]$offset = 0,
            [Parameter(ParameterSetName = 'noauto')]
            [int]$limit = 1000,
            [Parameter(ParameterSetName = 'auto')]
            [Switch]$autopage,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        If ($PSCmdlet.ParameterSetName -like "auto")
        {
            $foldlist = $adminclient.FoldersManager.GetFolderItemsAsync($folderid, $limit, $offset, $fields, $true)
        }
        Else
        {
            $foldlist = $adminclient.FoldersManager.GetFolderItemsAsync($folderid, $limit, $offset, $fields, $false)
        }
        $foldlist.Wait()
        If ($foldlist.IsFaulted -eq $true)
        {
            Write-error $foldlist.Exception.InnerException
            return
        }
        Else
        {
            return $foldlist.Result
        }
    }
    function new-boxfoldersharelink
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$folderid,
            [ValidateSet("open", "collaborators", "company")]
            [System.String]$accesstype = "open",
            [String]$password,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $sharelink = [Box.V2.Models.BoxSharedLinkRequest]::new()
        $sharelink.Access = $accesstype
        If ($PSBoundParameters.Keys -contains "password")
        {
            $sharelink.Password = $password
        }
        $sharelinkreq = $adminclient.FoldersManager.CreateSharedLinkAsync($folderid, $sharelink, $fields)
        $sharelinkreq.Wait()
        If ($sharelinkreq.IsFaulted -eq $true)
        {
            Write-error $sharelinkreq.Exception.InnerException
            return
        }
        Else
        {
            return $sharelinkreq.Result
        }
    }
    function copy-boxfolder
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$folderid,
            [Parameter(Mandatory = $true)]
            [String]$parentfolderid,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $folreq = @{
            id = "$folderid"
            parent = @{
                id = "$parentfolderid"
            }
        }
        $proc = $adminclient.FoldersManager.CopyAsync($folreq, $fields)
        $proc.Wait()
        If ($proc.IsFaulted -eq $true)
        {
            Write-error $proc.Exception.InnerException
            return
        }
        Else
        {
            return $proc.Result
        }
    }
    
    function remove-boxfolder
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$folderid,
            [Switch]$recurse
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        If ($recurse)
        {
            $folddelete = $adminclient.FoldersManager.DeleteAsync($folderid, $true)
        }
        Else
        {
            $folddelete = $adminclient.FoldersManager.DeleteAsync($folderid, $false)
        }
        $folddelete.Wait()
        If ($folddelete.IsFaulted -eq $true)
        {
            Write-error $folddelete.Exception.InnerException
            return
        }
        Else
        {
            return $folddelete.Result
        }
    }
    function copy-boxfile
    {
        param (
            [Parameter(Mandatory = $true)]
            [System.String]$fileid,
            [Parameter(Mandatory = $true)]
            [String]$parentfolderid,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $copyreq = @{
            id = "$fileid"
            parent = @{
                id = "$parentfolderid"
            }
        }
        $copyfile = $adminclient.FilesManager.CopyAsync($copyreq, $fields)
        $copyfile.Wait()
        If ($copyfile.IsFaulted -eq $true)
        {
            Write-error $copyfile.Exception.InnerException
            return
        }
        Else
        {
            return $copyfile.Result
        }
    }
    function remove-boxfoldersharedlink
    {
        param (
            [Parameter(Mandatory = $true)]
            [System.String]$folderid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $delshare = $adminclient.FoldersManager.DeleteSharedLinkAsync($folderid)
        $delshare.Wait()
        If ($delshare.IsFaulted -eq $true)
        {
            Write-error $delshare.Exception.InnerException
            return
        }
        Else
        {
            return $delshare.result
        }
    }
    function get-boxfolderinfo
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$folderid,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $folinfo = $adminclient.FoldersManager.GetInformationAsync($folderid, $fields)
        $folinfo.Wait()
        If ($folinfo.IsFaulted -eq $true)
        {
            Write-error $folinfo.Exception.InnerException
            return
        }
        Else
        {
            return $folinfo.Result
        }
        
    }
    function get-boxfoldercollaborations
    {
        param (
            [Parameter(Mandatory = $true)]
            [ValidateNotNullOrEmpty][String]$folderid,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $foldcollab = $adminclient.FoldersManager.GetCollaborationsAsync($folderid, $fields)
        $foldcollab.Wait()
        If ($foldcollab.IsFaulted -eq $true)
        {
            Write-error $foldcollab.Exception.InnerException
            return
        }
        Else
        {
            return $foldcollab.Result
        }
    }
    function Get-boxtrashedfolderitems
    {
        [CmdletBinding(DefaultParameterSetName = "autopage")]
        param (
            [Parameter(ParameterSetName = 'autopage')]
            [switch]$autopage,
            [Parameter(ParameterSetName = "noautopage")]
            [int]$limit = 1000,
            [Parameter(ParameterSetName = 'noautopage')]
            [int]$offset = 0,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        If ($PSCmdlet.ParameterSetName -like "autopage")
        {
            $trasheditems = $adminclient.FoldersManager.GetTrashItemsAsync($limit, $offset, $fields, $true)
        }
        Else
        {
            $trasheditems = $adminclient.FoldersManager.GetTrashItemsAsync($limit, $offset, $fields, $false)
        }
        $trasheditems.Wait()
        If ($trasheditems.IsFaulted -eq $true)
        {
            Write-error $trasheditems.Exception.InnerException
            return
        }
        Else
        {
            return $trasheditems.Result
        }
    }
    function get-trashedboxfolder
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$folderid,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $trashfold = $adminclient.FoldersManager.GetTrashedFolderAsync($folderid, $fields)
        $trashfold.Wait()
        If ($trashfold.IsFaulted -eq $true)
        {
            Write-error $trashfold.Exception.InnerException
            return
        }
        Else
        {
            return $trashfold.Result
        }
    }
    function remove-boxtrashfolder
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$folderid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $purgefold = $adminclient.FoldersManager.PurgeTrashedFolderAsync($folderid)
        $purgefold.Wait()
        If ($purgefold.IsFaulted -eq $true)
        {
            Write-error $purgefold.Exception.InnerException
            return
        }
        Else
        {
            return $purgefold.Result
        }
    }
    function restore-trashedboxfolder
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$trashedfolderid,
            [String]$restoretofolderid,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        If ($PSBoundParameters.Keys -contains "restoretofolderid")
        {
            $foldreq = @{
                id = "$trashedfolderid"
                parent = @{
                    id = "$restoretofolderid"
                }
            }
        }
        Else
        {
            $foldreq = @{
                id = "$trashedfolderid"
            }
        }
        
        $restorefold = $adminclient.FoldersManager.RestoreTrashedFolderAsync($foldreq, $fields)
        $restorefold.Wait()
        If ($restorefold.IsFaulted -eq $true)
        {
            Write-error $restorefold.Exception.InnerException
            return
        }
        Else
        {
            return $restorefold.Result
        }
    }
    
    function set-boxfolderinfo
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$folderid,
            [String]$parentfolderid,
            [String]$description,
            [Switch]$folderuploademail,
            [String]$name,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $foldreq = New-Object Box.V2.Models.BoxFolderRequest
        $foldreq.Id = $folderid
        If ($PSBoundParameters.Keys -contains "parentfolderid")
        {
            $entity = New-Object Box.V2.Models.BoxRequestEntity
            $entity.Id = $parentfolderid
            $entity.Type = "folder"
            $foldreq.Parent = $entity
        }
        If ($PSBoundParameters.Keys -contains "description")
        {
            $foldreq.Description = $description
        }
        If ($folderuploademail)
        {
            $email = New-Object Box.V2.Models.BoxEmailRequest
            $foldreq.FolderUploadEmail = $email
        }
        If ($PSBoundParameters.Keys -contains "name")
        {
            $foldreq.Name = $name
        }
        $folderupdate = $adminclient.FoldersManager.UpdateInformationAsync($foldreq, $fields)
        $folderupdate.Wait()
        If ($folderupdate.IsFaulted -eq $true)
        {
            Write-error $folderupdate.Exception.InnerException
            return
        }
        Else
        {
            return $folderupdate.Result
        }
    }
    function get-boxcollections
    {
    If ($adminclient -eq $null)
    {
        Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
        return
    }
    
        $getcoll = $adminclient.CollectionsManager.GetCollectionsAsync()
        $getcoll.Wait()
        If ($getcoll.IsFaulted -eq $true)
        {
            Write-error $getcoll.Exception.InnerException
            return
        }
        Else
        {
            return $getcoll.Result
        }
    }
    function Get-boxcollectionitems
    {
        [CmdletBinding(DefaultParameterSetName = "autopage")]
        param (
            [Parameter(Mandatory = $true)]
            [String]$collectionid,
            [Parameter(ParameterSetName = "noauto")]
            [ValidateNotNull][int]$offset = 0,
            [Parameter(ParameterSetName = 'noauto')]
            [ValidateNotNull][int]$limit = 1000,
            [Parameter(ParameterSetName = 'autopage')]
            [switch]$autopaginate,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        If ($PSCmdlet.ParameterSetName -like "noauto")
        {
            $boxcollections = $adminclient.CollectionsManager.GetCollectionItemsAsync($collectionid, $limit, $offset, $fields, $false)
        }
        Else
        {
            $boxcollections = $adminclient.CollectionsManager.GetCollectionItemsAsync($collectionid, $limit, $offset, $fields, $true)
        }
        $boxcollections.Wait()
        If ($boxcollections.IsFaulted -eq $true)
        {
            Write-error $boxcollections.Exception.InnerException
            return
        }
        Else
        {
            return $boxcollections.Result
        }
    }
    function addremove-boxcollectionsforfolder
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$folderid,
            [Parameter(Mandatory = $true)]
            [String]$collectionid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $boxent = New-object Box.V2.Models.BoxRequestEntity
        $boxent.Id = $collectionid
        $boxent.Type = "folder"
        $boxcollreq = New-Object Box.V2.Models.BoxCollectionsRequest
        $boxcollreq.Collections = $boxent
        $boxcollectionreq = $adminclient.CollectionsManager.CreateOrDeleteCollectionsForFolderAsync($folderid, $boxcollreq)
        $boxcollectionreq.Wait()
        If ($boxcollectionreq.IsFaulted -eq $true)
        {
            Write-error $boxcollectionreq.Exception.InnerException
            return
        }
        Else
        {
            return $boxcollectionreq.Result
        }
    }
    function addremove-boxcollectionsforfile
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$fileid,
            [Parameter(Mandatory = $true)]
            [String]$collectionid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $boxentr = New-object Box.V2.Models.BoxRequestEntity
        $boxentr.Id = $collectionid
        $boxentr.Type = "file"
        $boxcollreqr = New-Object Box.V2.Models.BoxCollectionsRequest
        $boxcollreqr.Collections = $boxentr
        $boxcollectionreqr = $adminclient.CollectionsManager.CreateOrDeleteCollectionsForFolderAsync($fileid, $boxcollreqr)
        $boxcollectionreqr.Wait()
        If ($boxcollectionreqr.IsFaulted -eq $true)
        {
            Write-error $boxcollectionreqr.Exception.InnerException
            return
        }
        Else
        {
            return $boxcollectionreqr.Result
        }
    }
    function get-boxfileinfo
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$fileid,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $fileinfo = $adminclient.FilesManager.GetInformationAsync($fileid, $fields)
        $fileinfo.Wait()
        If ($fileinfo.IsFaulted -eq $true)
        {
            Write-error $fileinfo.Exception.InnerException
            return
        }
        Else
        {
            return $fileinfo.Result
        }
    }
    function new-boxcomment
    {
        param (
            [Parameter(Mandatory = $true)]
            [ValidateSet("file", "discussion", "comment")]
            [String]$boxtype,
            [Parameter(Mandatory = $true)]
            [String]$entityid,
            [Parameter(Mandatory = $true)]
            [String]$comment,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $entreq = New-Object Box.V2.Models.BoxRequestEntity
        $entreq.Id = $entityid
        $entreq.Type = $boxtype
        $commreq = New-Object Box.V2.Models.BoxCommentRequest
        $commreq.Item = $entreq
        $commreq.Message = $comment
        $createcomment = $adminclient.CommentsManager.AddCommentAsync($commreq, $fields)
        $createcomment.Wait()
        If ($createcomment.IsFaulted -eq $true)
        {
            Write-error $createcomment.Exception.InnerException
            return
        }
        Else
        {
            return $createcomment.Result
        }
    }
    function remove-boxcomment
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$commentid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $deletecomment = $adminclient.CommentsManager.DeleteAsync($commentid)
        $deletecomment.Wait()
        If ($deletecomment.IsFaulted -eq $true)
        {
            Write-error $deletecomment.Exception.InnerException
            return
        }
        Else
        {
            return $deletecomment.Result
        }
    }
    function get-boxfilecomment
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$fileid,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $filecomments = $adminclient.FilesManager.GetCommentsAsync($fileid, $fields)
        $filecomments.Wait()
        If ($filecomments.IsFaulted -eq $true)
        {
            Write-error $filecomments.Exception.InnerException
            return
        }
        Else
        {
            return $filecomments.Result
        }
    }
    function Get-boxcommentinfo
    {
        param (
            [Parameter(Mandatory = $true)]
            [System.String]$commentid,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $commentinfo = $adminclient.CommentsManager.GetInformationAsync($commentid, $fields)
        $commentinfo.Wait()
        If ($commentinfo.IsFaulted -eq $true)
        {
            Write-error $commentinfo.Exception.InnerException
            return
        }
        Else
        {
            return $commentinfo.Result
        }
        
    }
    function set-boxcomment
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$commentid,
            [Parameter(Mandatory = $true)]
            [String]$comment,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        Try
        {
            $commenttest = Get-boxcommentinfo -commentid $commentid -ErrorAction Stop
        }
        Catch
        {
            Write-Error "The id is not associated with a valid comment."
            return
        }
        $commreq = New-Object Box.V2.Models.BoxCommentRequest
        $commreq.Message = $comment
        $updatecomment = $adminclient.CommentsManager.AddCommentAsync($commentid, $commreq, $fields)
        $updatecomment.Wait()
        If ($updatecomment.IsFaulted -eq $true)
        {
            Write-Error $updatecomment.Exception.InnerException
            return
        }
        Else
        {
            return $updatecomment.Result
        }
        
    }
    function get-boxenterpriseevents
    {
        [CmdletBinding(DefaultParameterSetName = "default")]
        param (
            [int]$limit = 500,
            [string]$offset = $null,
            [System.String[]]$eventtypes = $null,
            [datetime]$createdbefore,
            [datetime]$createdafter
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        If ($PSBoundParameters -contains "createdbefore")
        {
            If ($PSBoundParameters -contains "createdafter")
            {
                $getboxevents = $adminclient.EventsManager.EnterpriseEventsAsync($limit, $offset, $eventtypes, $createdafter, $createdbefore)
            }
            Else
            {
                $getboxevents = $adminclient.EventsManager.EnterpriseEventsAsync($limit, $offset, $eventtypes, $null, $createdbefore)
            }
        }
        Else
        {
            If ($PSBoundParameters -contains "createdafter")
            {
                $getboxevents = $adminclient.EventsManager.EnterpriseEventsAsync($limit, $offset, $eventtypes, $createdafter)
            }
            Else
            {
                $getboxevents = $adminclient.EventsManager.EnterpriseEventsAsync($limit, $offset, $eventtypes)
            }
        }
        
        $getboxevents.Wait()
        If ($getboxevents.IsFaulted -eq $true)
        {
            Write-Error $getboxevents.Exception.InnerException
            return
        }
        Else
        {
            return $getboxevents.result
        }
    }
    function get-boxuserevents
    {
        param (
            [int]$limit = 500,
            [ValidateSet("all", "changes", "sync")]
            [string]$usereventtype = "all",
            [string]$streamposition = "now",
            [switch]$dedupeEvents
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        If ($dedupeEvents -eq $true)
        {
            $userevents = $adminclient.EventsManager.UserEventsAsync($limit, $usereventtype, $streamposition, $true)
        }
        Else
        {
            $userevents = $adminclient.EventsManager.UserEventsAsync($limit, $usereventtype, $streamposition, $false)
        }
        $userevents.Wait()
        If ($userevents.IsFaulted -eq $true)
        {
            Write-Error $userevents.Exception.InnerException
            return
        }
        Else
        {
            return $userevents.Result
        }
        
    }
    
    function upload-boxfilenewversion
    {
        [CmdletBinding()]
        param (
            [Parameter(Mandatory = $true)]
            [String]$filename,
            [Parameter(Mandatory = $true)]
            [String]$fileid,
            [Parameter(Mandatory = $true)]
            [String]$path,
            [String[]]$fields = $null,
            [Parameter(Mandatory = $true)]
            [system.TimeSpan]$timespan
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        If (!(Test-Path $path))
        {
            Write-Error "The file $path does not exist. Try again."
            return
        }
        $filestream = [System.IO.File]::OpenRead($path)
        $fileversionup = $adminclient.FilesManager.UploadNewVersionAsync($filename, $fileid, $filestream, $null, $fields, $timespan, $null, $true, $null)
        $fileversionup.Wait()
        If ($fileversionup.IsFaulted -eq $true)
        {
            Write-error $fileversionup.Exception.InnerException
            return
        }
        Else
        {
            return $fileversionup.Result
        }
        
    }
    function new-boxfilesharelink
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$fileid,
            [ValidateSet("open", "collaborators", "company")]
            [String]$accesstype = "open",
            [String]$password,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $sharelink = [Box.V2.Models.BoxSharedLinkRequest]::new()
        $sharelink.Access = $accesstype
        If ($PSBoundParameters.Keys -contains "password")
        {
            $sharelink.Password = $password
        }
        $sharelinkreq = $adminclient.FilesManager.CreateSharedLinkAsync($fileid, $sharelink, $fields)
        $sharelinkreq.Wait()
        If ($sharelinkreq.IsFaulted -eq $true)
        {
            Write-error $sharelinkreq.Exception.InnerException
            return
        }
        Else
        {
            return $sharelinkreq.Result
        }
    }
    function remove-boxfile
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$fileid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $deletefile = $adminclient.FilesManager.DeleteAsync($fileid)
        $deletefile.Wait()
        If ($deletefile.IsFaulted -eq $true)
        {
            Write-error $deletefile.Exception.InnerException
            return
        }
        Else
        {
            return $deletefile.Result
        }
    }
    function get-boxfileversions
    {
        param (
            [Parameter(Mandatory = $true)]
            [System.String]$fileid,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $fileversions = $adminclient.FilesManager.ViewVersionsAsync($fileid, $fields)
        $fileversions.Wait()
        If ($fileversions.IsFaulted -eq $true)
        {
            Write-error $fileversions.Exception.InnerException
            return
        }
        Else
        {
            return $fileversions.Result
        }
        
    }
    function remove-boxoldfileversion
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$fileid,
            [Parameter(Mandatory = $true)]
            [String]$versionid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $removeversion = $adminclient.FilesManager.DeleteOldVersionAsync($fileid, $versionid)
        $removeversion.Wait()
        If ($removeversion.IsFaulted -eq $true)
        {
            Write-error $removeversion.Exception.InnerException
            return
        }
        Else
        {
            return $removeversion.Result
        }
        
    }
    function remove-boxfilesharelink
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$fileid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $deletesharelink = $adminclient.FilesManager.DeleteSharedLinkAsync($fileid)
        $deletesharelink.Wait()
        If ($deletesharelink.IsFaulted -eq $true)
        {
            Write-error $deletesharelink.Exception.InnerException
            return
        }
        Else
        {
            return $deletesharelink.Result
        }
        
    }
    function new-boxcollaborator
    {
        param (
            [Parameter(Mandatory = $true)]
            [ValidateSet("file", "discussion", "comment", "folder", "retention_policy", "enterprise", "user", "group", "web_link", "file_version", "metadata_template")]
            [String]$boxtype,
            [Parameter(Mandatory = $true)]
            $itemid,
            [Parameter(Mandatory = $true)]
            [String]$inviteduserid,
            [Parameter(Mandatory = $true)]
            [ValidateSet("Editor", "Viewer", "previewer", "Uploader", "PreviewerUploader", "ViewerUploader", "CoOwner")]
            [String]$role,
            [ValidateSet("accepted", "rejected")]
            [String]$status,
            [datetime]$expires,
            [System.String[]]$fields = $null,
            [Switch]$notify
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $boxent = New-object Box.V2.Models.BoxRequestEntity
        $boxent.Type = $boxtype
        $boxent.Id = $itemid
        $colluser = New-object Box.V2.Models.BoxCollaborationUserRequest
        $colluser.Id = $inviteduserid
        $collabreq = New-object Box.V2.Models.BoxCollaborationRequest
        $collabreq.Item = $boxent
        $collabreq.AccessibleBy = $colluser
        $collabreq.Role = $role
        If ($PSBoundParameters.Keys -contains "status")
        {
            $collabreq.Status = $status
        }
        If ($PSBoundParameters.Keys -contains "expires")
        {
            $collabreq.ExpiresAt = $expires
        }
        If ($PSBoundParameters.Keys -contains "notify")
        {
            $addcolla = $adminclient.CollaborationsManager.AddCollaborationAsync($collabreq, $fields, $true)
        }
        Else
        {
            $addcolla = $adminclient.CollaborationsManager.AddCollaborationAsync($collabreq, $fields, $false)
        }
        $addcolla.Wait()
        If ($addcolla.IsFaulted -eq $true)
        {
            Write-error $addcolla.Exception.InnerException
            return
        }
        Else
        {
            return $addcolla.Result
        }
        
    }
    function Get-boxcollaborationinfo
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$collaborationid,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $collabinfo = $adminclient.CollaborationsManager.GetCollaborationAsync($collaborationid, $fields)
        $collabinfo.Wait()
        If ($collabinfo.IsFaulted -eq $true)
        {
            Write-error $collabinfo.Exception.InnerException
            return
        }
        Else
        {
            return $collabinfo.Result
        }
        
    }
    function get-pendingboxcollaboration
    {
        param (
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $pendingcoll = $adminclient.CollaborationsManager.GetPendingCollaborationAsync($fields)
        $pendingcoll.Wait()
        If ($pendingcoll.IsFaulted -eq $true)
        {
            Write-error $pendingcoll.Exception.InnerException
            return
        }
        Else
        {
            return $pendingcoll.Result
        }
        
    }
    function remove-boxcollaboration
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$collaborationid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $removecollab = $adminclient.CollaborationsManager.RemoveCollaborationAsync($collaborationid)
        $removecollab.Wait()
        If ($removecollab.IsFaulted -eq $true)
        {
            Write-error $removecollab.Exception.InnerException
            return
        }
        Else
        {
            return $removecollab.Result
        }
        
    }
    function get-boxfilecollaborations
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$fileid,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $filecollab = $adminclient.FilesManager.GetCollaborationsAsync($fileid, $fields)
        $filecollab.Wait()
        If ($filecollab.IsFaulted -eq $true)
        {
            Write-error $filecollab.Exception.InnerException
            return
        }
        Else
        {
            return $filecollab.Result
        }
        
    }
    function get-boxfiledownloaduri
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$fileid,
            [String]$versionid = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $filedown = $adminclient.FilesManager.GetDownloadUriAsync($fileid, $versionid)
        $filedown.Wait()
        If ($filedown.IsFaulted -eq $true)
        {
            Write-error $filedown.Exception.InnerException
            return
        }
        Else
        {
            return $filedown.Result
        }
        
    }
    function get-boxfiletasks
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$fileid,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $filetasks = $adminclient.FilesManager.GetFileTasks($fileid, $fields)
        $filetasks.Wait()
        If ($filetasks.IsFaulted -eq $true)
        {
            Write-error $filetasks.Exception.InnerException
            return
        }
        Else
        {
            return $filetasks.Result
        }
        
    }
    function lock-boxfile
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$fileid,
            [DateTime]$expiresat,
            [Switch]$preventdownload
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $lock = New-Object Box.V2.Models.BoxFileLock
        If ($PSBoundParameters.Keys -contains "expiresat")
        {
            $lock.ExpiresAt = $expiresat
        }
        If ($preventdownload)
        {
            $lock.IsDownloadPrevented = $true
        }
        Else
        {
            $lock.IsDownloadPrevented = $false
        }
        $lockreq = New-Object Box.V2.Models.BoxFileLockRequest
        $lockreq.Lock = $lock
        $lockfile = $adminclient.FilesManager.LockAsync($lockreq, $fileid)
        $lockfile.Wait()
        If ($lockfile.IsFaulted -eq $true)
        {
            Write-error $lockfile.Exception.InnerException
            return
        }
        Else
        {
            return $lockfile.Result
        }
        
    }
    function get-boxfilelock
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$fileid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $filelockinfo = $adminclient.FilesManager.GetLockAsync($fileid)
        $filelockinfo.Wait()
        If ($filelockinfo.IsFaulted -eq $true)
        {
            Write-error $filelockinfo.Exception.InnerException
            return
        }
        Else
        {
            return $filelockinfo.Result
        }
        
    }
    function get-boxfilepreview
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$fileid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $filepreview = $adminclient.FilesManager.GetPreviewLinkAsync($fileid)
        $filepreview.Wait()
        If ($filepreview.IsFaulted -eq $true)
        {
            Write-error $filepreview.Exception.InnerException
            return
        }
        Else
        {
            return $filepreview.Result
        }
        
    }
    function get-boxfilethumbnail
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$fileid,
            [int]$minheight = $null,
            [int]$minwidth = $null,
            [int]$maxheight = $null,
            [int]$maxwidth = $null,
            [switch]$handleretry,
            [switch]$throttle
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        If ($PSBoundParameters.Keys -contains "handleretry")
        {
            If ($PSBoundParameters.Keys -contains "throttle")
            {
                $thumbnail = $adminclient.FilesManager.GetThumbnailAsync($fileid, $minheight, $minwidth, $maxheight, $maxwidth, $true, $true)
            }
            Else
            {
                $thumbnail = $adminclient.FilesManager.GetThumbnailAsync($fileid, $minheight, $minwidth, $maxheight, $maxwidth, $false, $true)
            }
        }
        Else
        {
            If ($PSBoundParameters.Keys -contains "throttle")
            {
                $thumbnail = $adminclient.FilesManager.GetThumbnailAsync($fileid, $minheight, $minwidth, $maxheight, $maxwidth, $true, $false)
            }
            Else
            {
                $thumbnail = $adminclient.FilesManager.GetThumbnailAsync($fileid, $minheight, $minwidth, $maxheight, $maxwidth, $false, $false)
            }
        }
        $thumbnail.Wait()
        If ($thumbnail.IsFaulted -eq $true)
        {
            Write-error $thumbnail.Exception.InnerException
            return
        }
        Else
        {
            return $thumbnail.Result
        }
        
    }
    function get-trashedboxfile
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$fileid,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $trashfile = $adminclient.FilesManager.GetTrashedAsync($fileid, $fields)
        $trashfile.Wait()
        If ($trashfile.IsFaulted -eq $true)
        {
            Write-error $trashfile.Exception.InnerException
            return
        }
        Else
        {
            return $trashfile.Result
        }
        
    }
    function set-boxfileversion
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$fileid,
            [Parameter(Mandatory = $true)]
            [String]$versionid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $setversion = $adminclient.FilesManager.PromoteVersionAsync($fileid, $versionid)
        $setversion.Wait()
        If ($setversion.IsFaulted -eq $true)
        {
            Write-error $setversion.Exception.InnerException
            return
        }
        Else
        {
            return $setversion.Result
        }
        
    }
    function remove-boxtrashfile
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$fileid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $deletefile = $adminclient.FilesManager.PurgeTrashedAsync($fileid)
        $deletefile.Wait()
        If ($deletefile.IsFaulted -eq $true)
        {
            Write-error $deletefile.Exception.InnerException
            return
        }
        Else
        {
            return $deletefile.Result
        }
        
    }
    function restore-boxtrashfile
    {
        param (
            [Parameter(Mandatory = $true)]
            [System.String]$fileid,
            [String]$parentfolderid,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $filereq = New-Object box.V2.Models.BoxFileRequest
        $filereq.Id = $fileid
        If ($PSBoundParameters -contains "parentfolderid")
        {
            $boxent = New-Object box.V2.Models.BoxRequestEntity
            $boxent.Id = $parentfolderid
            $boxent.Type = "folder"
            $filereq.Parent = $boxent
        }
        $restorefile = $adminclient.FilesManager.RestoreTrashedAsync($filereq, $fields)
        $restorefile.Wait()
        If ($restorefile.IsFaulted -eq $true)
        {
            Write-error $restorefile.Exception.InnerException
            return
        }
        Else
        {
            return $restorefile.Result
        }
        
    }
    function unlock-boxfile
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$fileid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $unlockfile = $adminclient.FilesManager.UnLock($fileid)
        $unlockfile.Wait()
        If ($unlockfile.IsFaulted -eq $true)
        {
            Write-error $unlockfile.Exception.InnerException
            return
        }
        Else
        {
            return $unlockfile.Result
        }
        
    }
    function set-boxfileinfo
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$fileid,
            [String]$parentfoldid,
            [String]$description,
            [String]$name,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $filereq = New-Object Box.V2.Models.BoxFileRequest
        $filereq.Id = $fileid
        If ($PSBoundParameters.Keys -contains "parentfoldid")
        {
            $parentent = New-Object Box.V2.Models.BoxRequestEntity
            $parentent.Id = $parentfoldid
            $parentent.Type = "folder"
            $filereq.Parent = $parentent
        }
        If ($PSBoundParameters.Keys -contains "description")
        {
            $filereq.Description = $description
        }
        If ($PSBoundParameters.Keys -contains "name")
        {
            $filereq.Name = $name
        }
        $updatefile = $adminclient.FilesManager.UpdateInformationAsync($filereq, $fields)
        $updatefile.Wait()
        If ($updatefile.IsFaulted -eq $true)
        {
            Write-error $updatefile.Exception.InnerException
            return
        }
        Else
        {
            return $updatefile.Result
        }
        
    }
    function get-allboxgroups
    {
        [CmdletBinding(DefaultParameterSetName = "auto")]
        param (
            [Parameter(ParameterSetName = 'noauto')]
            [int]$limit = 1000,
            [Parameter(ParameterSetName = 'noauto')]
            [int]$offset = 0,
            [Parameter(ParameterSetName = 'auto')]
            [switch]$autopage,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        If ($PSCmdlet.ParameterSetName -like "noauto")
        {
            $boxgroup = $adminclient.GroupsManager.GetAllGroupsAsync($limit, $offset, $fields, $false)
        }
        Else
        {
            $boxgroup = $adminclient.GroupsManager.GetAllGroupsAsync($limit, $offset, $fields, $true)
        }
        $boxgroup.Wait()
        If ($boxgroup.IsFaulted -eq $true)
        {
            Write-error $boxgroup.Exception.InnerException
            return
        }
        Else
        {
            return $boxgroup.Result
        }
        
    }
    
    function new-boxgroup
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$name,
            [String]$description,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $groupreq = New-Object Box.V2.Models.Request.BoxGroupRequest
        $groupreq.Name = $name
        If ($PSBoundParameters.Keys -contains "description")
        {
            $groupreq.Description = $description
        }
        $creategroup = $adminclient.GroupsManager.CreateAsync($groupreq, $fields)
        $creategroup.Wait()
        If ($creategroup.IsFaulted -eq $true)
        {
            Write-error $creategroup.Exception.InnerException
            return
        }
        Else
        {
            return $creategroup.Result
        }
        
    }
    
    function remove-boxgroup
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$groupid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $deleteproc = $adminclient.GroupsManager.DeleteAsync($groupid)
        $deleteproc.Wait()
        If ($deleteproc.IsFaulted -eq $true)
        {
            Write-error $deleteproc.Exception.InnerException
            return
        }
        Else
        {
            return $deleteproc.Result
        }
        
    }
    
    function get-boxgroup
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$groupid,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $boxgroup = $adminclient.GroupsManager.GetGroupAsync($groupid, $fields)
        $boxgroup.Wait()
        If ($boxgroup.IsFaulted -eq $true)
        {
            Write-error $boxgroup.Exception.InnerException
            return
        }
        Else
        {
            return $boxgroup.Result
        }
        
    }
    
    function get-boxgroupmembershipforgroup
    {
        [CmdletBinding(DefaultParameterSetName = "auto", SupportsShouldProcess = $true)]
        param (
            [Parameter(Mandatory = $true)]
            [String]$groupid,
            [Parameter(ParameterSetName = "noauto")]
            [int]$limit = 1000,
            [Parameter(ParameterSetName = "noauto")]
            [int]$offset = 0,
            [Parameter(ParameterSetName = 'auto')]
            [Switch]$autopage,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        If ($PSCmdlet.ParameterSetName -like "noauto")
        {
            $groupmembers = $adminclient.GroupsManager.GetAllGroupMembershipsForGroupAsync($groupid, $limit, $offset, $fields, $false)
        }
        Else
        {
            $groupmembers = $adminclient.GroupsManager.GetAllGroupMembershipsForGroupAsync($groupid, $limit, $offset, $fields, $true)
        }
        $groupmembers.Wait()
        If ($groupmembers.IsFaulted -eq $true)
        {
            Write-error $groupmembers.Exception.InnerException
            return
        }
        Else
        {
            return $groupmembers.Result
        }
        
    }
    
    function get-boxgroupmembershipforuser
    {
        [CmdletBinding(DefaultParameterSetName = "auto")]
        param (
            [Parameter(Mandatory = $true)]
            [String]$userid,
            [Parameter(ParameterSetName = "noauto")]
            [int]$limit = 1000,
            [Parameter(ParameterSetName = 'noauto')]
            [int]$offset = 0,
            [Parameter(ParameterSetName = 'auto')]
            [Switch]$autopage,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        If ($PSCmdlet.ParameterSetName -like "noauto")
        {
            $usermember = $adminclient.GroupsManager.GetAllGroupMembershipsForUserAsync($userid, $limit, $offset, $fields, $false)
        }
        Else
        {
            $usermember = $adminclient.GroupsManager.GetAllGroupMembershipsForUserAsync($userid, $limit, $offset, $fields, $true)
        }
        $usermember.Wait()
        If ($usermember.IsFaulted -eq $true)
        {
            Write-error $usermember.Exception.InnerException
            return
        }
        Else
        {
            return $usermember.Result
        }
        
    }
    
    function add-boxgroupmember
    {
        param (
            [Parameter(Mandatory = $true)]
            [string]$userid,
            [Parameter(Mandatory = $true)]
            [String]$groupid,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $userreq = New-Object box.V2.Models.BoxRequestEntity
        $userreq.Id = $userid
        $userreq.Type = "user"
        $groupreq = New-Object Box.V2.Models.Request.BoxGroupRequest
        $groupreq.Id = $groupid
        $memberreq = New-Object Box.V2.Models.Request.BoxGroupMembershipRequest
        $memberreq.User = $userreq
        $memberreq.Group = $groupreq
        $memberreq.Role = "member"
        $addgroupmem = $adminclient.GroupsManager.AddMemberToGroupAsync($memberreq, $fields)
        $addgroupmem.Wait()
        If ($addgroupmem.IsFaulted -eq $true)
        {
            Write-error $addgroupmem.Exception.InnerException
            return
        }
        Else
        {
            return $addgroupmem.Result
        }
        
    }
    function remove-boxgroupmembership
    {
        param (
            [Parameter(Mandatory = $true)]
            [string]$groupmembershipid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $removemember = $adminclient.GroupsManager.DeleteGroupMembershipAsync($groupmembershipid)
        $removemember.Wait()
        If ($removemember.IsFaulted -eq $true)
        {
            Write-error $removemember.Exception.InnerException
            return
        }
        Else
        {
            return $removemember.Result
        }
        
    }
    
    function get-boxgroupmembership
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$memberid,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $getboxgroup = $adminclient.GroupsManager.GetGroupMembershipAsync($memberid, $fields)
        $getboxgroup.Wait()
        If ($getboxgroup.IsFaulted -eq $true)
        {
            Write-error $getboxgroup.Exception.InnerException
            return
        }
        Else
        {
            return $getboxgroup.Result
        }
        
    }
    
    function set-boxgroup
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$groupid,
            [String]$name,
            [String]$description,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $groupreq = New-Object box.V2.Models.Request.BoxGroupRequest
        If ($PSBoundParameters.Keys -contains "name")
        {
            $groupreq.Name = $name
        }
        If ($PSBoundParameters.Keys -contains "description")
        {
            $groupreq.Description = $description
        }
        $updategroup = $adminclient.GroupsManager.UpdateAsync($groupid, $groupreq, $fields)
        $updategroup.Wait()
        If ($updategroup.IsFaulted -eq $true)
        {
            Write-error $updategroup.Exception.InnerException
            return
        }
        Else
        {
            return $updategroup.Result
        }
        
    }
    
    function set-boxgroupmembership
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$membershipid,
            [String]$userid,
            [String]$groupid,
            [String]$memberrole,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $membreq = New-Object Box.V2.Models.Request.BoxGroupMembershipRequest
        If ($PSBoundParameters.Keys -contains "userid")
        {
            $userreq = New-Object Box.V2.Models.BoxRequestEntity
            $userreq.Id = $userid
            $userreq.Type = "user"
            $membreq.User = $userreq
        }
        If ($PSBoundParameters.Keys -contains "groupid")
        {
            $groupreq = New-Object Box.V2.Models.Request.BoxGroupRequest
            $groupreq.Id = $groupid
            $membreq.Group = $groupreq
        }
        If ($PSBoundParameters.Keys -contains "memberrole")
        {
            $membreq.Role = $memberrole
        }
        $updatemem = $adminclient.GroupsManager.UpdateGroupMembershipAsync($membershipid, $membreq, $fields)
        $updatemem.Wait()
        If ($updatemem.IsFaulted -eq $true)
        {
            Write-error $updatemem.Exception.InnerException
            return
        }
        Else
        {
            return $updatemem.Result
        }
        
    }
    
    function new-boxlegalholdpolicy
    {
        [CmdletBinding(DefaultParameterSetName = "ongoing")]
        param (
            [Parameter(Mandatory = $true)]
            [String]$name,
            [Parameter(Mandatory = $true)]
            [ValidateLength(1, 500)]
            [String]$description,
            [Parameter(Mandatory = $true, ParameterSetName = "settime")]
            [DateTime]$startedat,
            [Parameter(Mandatory = $true, ParameterSetName = "settime")]
            [DateTime]$endedat,
            [Parameter(ParameterSetName = 'ongoing')]
            [Switch]$isongoing,
            [ValidateLength(0, 500)]
            [String]$releasenotes
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $legreq = New-Object Box.V2.Models.BoxLegalHoldPolicyRequest
        $legreq.PolicyName = $name
        $legreq.Description = $description
        If ($PSCmdlet.ParameterSetName -like "settime")
        {
            $legreq.FilterStartedAt = $startedat
            $legreq.FilterEndedAt = $endedat
        }
        Else
        {
            $legreq.isOngoing = $true
        }
        If ($PSBoundParameters.Keys -contains "releasenotes")
        {
            $legreq.ReleaseNotes = $releasenotes
        }
        $newlegal = $adminclient.LegalHoldPoliciesManager.CreateLegalHoldPolicyAsync($legreq)
        $newlegal.Wait()
        If ($newlegal.IsFaulted -eq $true)
        {
            Write-error $newlegal.Exception.InnerException
            return
        }
        Else
        {
            return $newlegal.Result
        }
        
    }
    
    function new-boxlegalholdpolicyassignment
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$policyid,
            [Parameter(Mandatory = $true)]
            [String]$assigntoid,
            [Parameter(Mandatory = $true)]
            [ValidateSet("file", "folder", "user", "file_version")]
            [String]$assigntotype
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $entreq = New-Object Box.V2.Models.BoxRequestEntity
        $entreq.Id = $assigntoid
        $entreq.Type = $assigntotype
        $assignreq = New-Object Box.V2.Models.BoxLegalHoldPolicyAssignmentRequest
        $assignreq.AssignTo = $entreq
        $assignreq.PolicyId = $policyid
        $newassignment = $adminclient.LegalHoldPoliciesManager.CreateAssignmentAsync($assignreq)
        $newassignment.Wait()
        If ($newassignment.IsFaulted -eq $true)
        {
            Write-error $newassignment.Exception.InnerException
            return
        }
        Else
        {
            return $newassignment.Result
        }
        
        
    }
    
    function remove-boxlegalholdpolicy
    {
        param (
        [Parameter(Mandatory = $true)]
        [String]$policyid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $deletepolicy = $adminclient.LegalHoldPoliciesManager.DeleteLegalHoldPolicyAsync($policyid)
        $deletepolicy.Wait()
        If ($deletepolicy.IsFaulted -eq $true)
        {
            Write-error $deletepolicy.Exception.InnerException
            return
        }
        Else
        {
            return $deletepolicy.Result
        }
        
    }
    
    function remove-boxlegalholdpolicyassignment
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$assignmentid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $removeassign = $adminclient.LegalHoldPoliciesManager.DeleteAssignmentAsync($assignmentid)
        $removeassign.Wait()
        If ($removeassign.IsFaulted -eq $true)
        {
            Write-error $removeassign.Exception.InnerException
            return
        }
        Else
        {
            return $removeassign.Result
        }
        
    }
    
    function get-boxlegalholdpolicyassignment
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$assignmentid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $getassign = $adminclient.LegalHoldPoliciesManager.GetAssignmentAsync($assignmentid)
        $getassign.Wait()
        If ($getassign.IsFaulted -eq $true)
        {
            Write-error $getassign.Exception.InnerException
            return
        }
        Else
        {
            return $getassign.Result
        }
        
    }
    
    function get-boxlegalholdpolicy
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$policyid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $getpolicy = $adminclient.LegalHoldPoliciesManager.GetLegalHoldPolicyAsync($policyid)
        $getpolicy.Wait()
        If ($getpolicy.IsFaulted -eq $true)
        {
            Write-error $getpolicy.Exception.InnerException
            return
        }
        Else
        {
            return $getpolicy.Result
        }
        
    }
    
    function get-allboxlegalholdpolicies
    {
        [CmdletBinding(DefaultParameterSetName = "autopage")]
        param (
            [String]$policyname = $null,
            [System.String[]]$fields = $null,
            [PArameter(ParameterSetName = "noauto")]
            [int]$limit = 1000,
            [Parameter(ParameterSetName = 'noauto')]
            [string]$marker = $null,
            [Parameter(ParameterSetName = 'autopage')]
            [Switch]$autopage
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        If ($PSCmdlet.ParameterSetName -like "noauto")
        {
            $alllegalpolicies = $adminclient.LegalHoldPoliciesManager.GetListLegalHoldPoliciesAsync($policyname, $fields, $limit, $marker, $false)
        }
        Else
        {
            $alllegalpolicies = $adminclient.LegalHoldPoliciesManager.GetListLegalHoldPoliciesAsync($policyname, $fields, $limit, $marker, $true)
        }
        $alllegalpolicies.Wait()
        If ($alllegalpolicies.IsFaulted -eq $true)
        {
            Write-error $alllegalpolicies.Exception.InnerException
            return
        }
        Else
        {
            return $alllegalpolicies.Result
        }
        
        
    }
    
    function get-allboxlegalholdpolicyassignments
    {
        [CmdletBinding(DefaultParameterSetName = "autopage")]
        param (
            [Parameter(Mandatory = $true)]
            [String]$policyid,
            [System.String[]]$fields = $null,
            [ValidateSet("file_version", "file", "folder", "user")]
            [String]$assigntotype = $null,
            [String]$assigntoid = $null,
            [Parameter(ParameterSetName = "noauto")]
            [int]$limit = 1000,
            [Parameter(ParameterSetName = 'noauto')]
            [String]$marker = $null,
            [Parameter(ParameterSetName = 'autopage')]
            [Switch]$autopage
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        If ($PSCmdlet.ParameterSetName -like "notauto")
        {
            $getassignments = $adminclient.LegalHoldPoliciesManager.GetAssignmentsAsync($policyid, $fields, $assigntotype, $assigntoid, $limit, $marker, $false)
        }
        Else
        {
            $getassignments = $adminclient.LegalHoldPoliciesManager.GetAssignmentsAsync($policyid, $fields, $assigntotype, $assigntoid, $limit, $marker, $true)
        }
        $getassignments.Wait()
        If ($getassignments.IsFaulted -eq $true)
        {
            Write-error $getassignments.Exception.InnerException
            return
        }
        Else
        {
            return $getassignments.Result
        }
        
    }
    
    function get-allboxfileversionlegalholds
    {
        [CmdletBinding(DefaultParameterSetName = "auto")]
        param (
            [parameter(Mandatory = $true)]
            [String]$policyid,
            [System.String[]]$fields = $null,
            [Parameter(ParameterSetName = "noauto")]
            [int]$limit = 1000,
            [Parameter(ParameterSetName = 'noauto')]
            [String]$marker = $null,
            [Parameter(ParameterSetName = 'auto')]
            [Switch]$autopage
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        If ($PSCmdlet.ParameterSetName -like "noauto")
        {
            $filever = $adminclient.LegalHoldPoliciesManager.GetFileVersionLegalHoldsAsync($policyid, $fields, $limit, $marker, $false)
        }
        Else
        {
            $filever = $adminclient.LegalHoldPoliciesManager.GetFileVersionLegalHoldsAsync($policyid, $fields, $limit, $marker, $false)
        }
        $filever.Wait()
        If ($filever.IsFaulted -eq $true)
        {
            Write-error $filever.Exception.InnerException
            return
        }
        Else
        {
            return $filever.Result
        }
        
    }
    
    function get-boxfileversionlegalhold
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$fileversionlegalholdid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $fileverleg = $adminclient.LegalHoldPoliciesManager.GetFileVersionLegalHoldAsync($fileversionlegalholdid)
        $fileverleg.Wait()
        If ($fileverleg.IsFaulted -eq $true)
        {
            Write-error $fileverleg.Exception.InnerException
            return
        }
        Else
        {
            return $fileverleg.Result
        }
        
    }
    
    function set-boxlegalholdpolicy
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$policyid,
            [String]$newpolicyname,
            [String]$newpolicydescription
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $legholreq = New-Object Box.V2.Models.BoxLegalHoldPolicyRequest
        If ($PSBoundParameters.Keys -contains "newpolicyname")
        {
            $legholreq.PolicyName = $newpolicyname
        }
        If ($PSBoundParameters.Keys -contains "newpolicydescription")
        {
            $legholreq.Description = $newpolicydescription
        }
        $setleghol = $adminclient.LegalHoldPoliciesManager.UpdateLegalHoldPolicyAsync($policyid, $legholreq)
        $setleghol.Wait()
        If ($setleghol.IsFaulted -eq $true)
        {
            Write-error $setleghol.Exception.InnerException
            return
        }
        Else
        {
            return $setleghol.Result
        }
        
    }
    
    function get-allboxMetadataCascadePolicies
    {
        [CmdletBinding(DefaultParameterSetName = "auto")]
        param (
            [Parameter(Mandatory = $true)]
            [String]$folderid,
            [String]$enterpriseid = $null,
            [PArameter(ParameterSetName = "noauto")]
            [int]$limit = 1000,
            [Parameter(ParameterSetName = 'noauto')]
            [String]$marker = $null,
            [System.String[]]$fields = $null,
            [Parameter(ParameterSetName = 'auto')]
            [Switch]$autopage
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        If ($PSCmdlet.ParameterSetName -like "noauto")
        {
            $getallmeta = $adminclient.MetadataCascadePolicyManager.GetAllMetadataCascadePoliciesAsync($folderid, $enterpriseid, $limit, $marker, $fields, $false)
        }
        Else
        {
            $getallmeta = $adminclient.MetadataCascadePolicyManager.GetAllMetadataCascadePoliciesAsync($folderid, $enterpriseid, $limit, $marker, $fields, $true)
        }
        $getallmeta.Wait()
        If ($getallmeta.IsFaulted -eq $true)
        {
            Write-error $getallmeta.Exception.InnerException
            return
        }
        Else
        {
            return $getallmeta.Result
        }
        
        
    }
    
    function get-boxmetadataCascadePolicy
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$policyid,
            [System.String[]]$fields = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $getmeta = $adminclient.MetadataCascadePolicyManager.GetCascadePolicyAsync($policyid, $fields)
        $getmeta.Wait()
        If ($getmeta.IsFaulted -eq $true)
        {
            Write-error $getmeta.Exception.InnerException
            return
        }
        Else
        {
            return $getmeta.Result
        }
        
    }
    
    function new-boxmetadatacascadepolicy
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$folderid,
            [Parameter(Mandatory = $true)]
            [ValidateSet("enterprise", "global")]
            [String]$scope,
            [Parameter(Mandatory = $true)]
            [String]$templatekey
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $newmetadata = $adminclient.MetadataCascadePolicyManager.CreateCascadePolicyAsync($folderid, $scope, $templatekey)
        $newmetadata.Wait()
        If ($newmetadata.IsFaulted -eq $true)
        {
            Write-error $newmetadata.Exception.InnerException
            return
        }
        Else
        {
            return $newmetadata.Result
        }
        
    }
    
    function remove-boxmetadatacascadepolicy
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$policyid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $removemeta = $adminclient.MetadataCascadePolicyManager.DeleteCascadePolicyAsync($policyid)
        $removemeta.Wait()
        If ($removemeta.IsFaulted -eq $true)
        {
            Write-error $removemeta.Exception.InnerException
            return
        }
        Else
        {
            return $removemeta.Result
        }
        
    }
    
    function apply-boxmetadatacascadepolicy
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$policyid,
            [Parameter(Mandatory = $true)]
            [ValidateSet("none", "overwrite")]
            [String]$conflictresolution
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $applymeta = $adminclient.MetadataCascadePolicyManager.ForceApplyCascadePolicyAsync($policyid, $conflictresolution)
        $applymeta.Wait()
        If ($applymeta.IsFaulted -eq $true)
        {
            Write-error $applymeta.Exception.InnerException
            return
        }
        Else
        {
            return $applymeta.Result
        }
        
    }
    
    function get-allboxfoldermetadatatemplates
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$folderid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $getfoldermetadata = $adminclient.MetadataManager.GetAllFolderMetadataTemplatesAsync($folderid)
        $getfoldermetadata.Wait()
        If ($getfoldermetadata.IsFaulted -eq $true)
        {
            Write-error $getfoldermetadata.Exception.InnerException
            return
        }
        Else
        {
            return $getfoldermetadata.Result
        }
        
    }
    
    function get-allboxfilemetadatatemplates
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$fileid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $getfilemetadata = $adminclient.MetadataManager.GetAllFolderMetadataTemplatesAsync($fileid)
        $getfilemetadata.Wait()
        If ($getfilemetadata.IsFaulted -eq $true)
        {
            Write-error $getfilemetadata.Exception.InnerException
            return
        }
        Else
        {
            return $getfilemetadata.Result
        }
        
    }
    
    function get-boxrecentitems
    {
        [CmdletBinding(DefaultParameterSetName = "auto")]
        param (
            [Parameter(ParameterSetName = "noauto")]
            [int]$limit = 1000,
            [Parameter(ParameterSetName = 'noauto')]
            [String]$marker = $null,
            [System.String[]]$fields = $null,
            [Parameter(ParameterSetName = 'auto')]
            [Switch]$autopage
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        If ($PSCmdlet.ParameterSetName -like "noauto")
        {
            $recentfiles = $adminclient.RecentItemsManager.GetRecentItemsAsync($limit, $marker, $fields, $false)
        }
        Else
        {
            $recentfiles = $adminclient.RecentItemsManager.GetRecentItemsAsync($limit, $marker, $fields, $true)
        }
        $recentfiles.Wait()
        If ($recentfiles.IsFaulted -eq $true)
        {
            Write-error $recentfiles.Exception.InnerException
            return
        }
        Else
        {
            return $recentfiles.Result
        }
        
    }
    function find-boxitem
    {
        param (
            [String]$keyword = $null,
            [int]$limit = 200,
            [int]$offset = 0,
            [System.String[]]$fields = $null,
            [ValidateSet("user_content", "enterprise_content")]
            [String]$scope = $null,
            [System.String[]]$fileextensions = $null,
            [System.Nullable[DateTime]]$createdAtRangeFromDate = $null,
            [System.Nullable[datetime]]$createdAtRangeToDate = $null,
            [System.Nullable[datetime]]$updatedAtRangeFromDate = $null,
            [System.Nullable[datetime]]$updatedAtRangeToDate = $null,
            [System.Nullable[int]]$sizeRangeLowerBoundBytes = $null,
            [System.Nullable[int]]$sizeRangeUpperBoundBytes = $null,
            [System.String[]]$ownerUserIds = $null,
            [System.String[]]$ancestorfolderids = $null,
            [ValidateSet("name", "description", "file_content", "comments", "tags")]
            [System.String[]]$contenttypes = $null,
            [ValidateSet("file", "folder", "web_link")]
            [String]$type = $null,
            [ValidateSet("trashed_only", "non_trashed_only")]
            [String]$trashContent = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $searchbox = $adminclient.SearchManager.SearchAsync($keyword, $limit, $offset, $fields, $scope, $fileextensions, $createdAtRangeFromDate, $createdAtRangeToDate, $updatedAtRangeFromDate, $updatedAtRangeToDate, $sizeRangeLowerBoundBytes, $sizeRangeUpperBoundBytes, $ownerUserIds, $ancestorfolderids, $contenttypes, $type, $trashContent)
        $searchbox.Wait()
        If ($searchbox.IsFaulted -eq $true)
        {
            Write-error $searchbox.Exception.InnerException
            return
        }
        Else
        {
            return $searchbox.Result
        }
        
    }
    
    function get-boxshareditembyurl
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$sharelink,
            [String]$password = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $shareitem = $adminclient.SharedItemsManager.SharedItemsAsync($sharelink, $password)
        $shareitem.Wait()
        If ($shareitem.IsFaulted -eq $true)
        {
            Write-error $shareitem.Exception.InnerException
            return
        }
        Else
        {
            return $shareitem.Result
        }
        
    }
    <#
    function get-allboxstoragepolicies
    {
        [CmdletBinding(DefaultParameterSetName = "auto")]
        param (
            [System.String[]]$fields = $null,
            [Parameter(ParameterSetName = "noauto")]
            [String]$marker = $null,
            [Parameter(ParameterSetName = 'noauto')]
            [int]$limit = 1000,
            [Parameter(ParameterSetName = 'auto')]
            [Switch]$autopage
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        If ($PSCmdlet.ParameterSetName -like "noauto")
        {
            $allstore = $adminclient.StoragePoliciesManager.GetListStoragePoliciesAsync($fields, $marker, $limit, $false)
        }
        Else
        {
            $allstore = $adminclient.StoragePoliciesManager.GetListStoragePoliciesAsync($fields, $marker, $limit, $true)
        }
        $allstore.Wait()
        If ($allstore.IsFaulted -eq $true)
        {
            Write-error $allstore.Exception.InnerException
            return
        }
        Else
        {
            return $allstore.Result
        }
         
    }
    #>

    
    function get-allboxwebhooks
    {
        [CmdletBinding(DefaultParameterSetName = "auto")]
        param (
            [Parameter(ParameterSetName = "noauto")]
            [int]$limit = 200,
            [Parameter(ParameterSetName = 'noauto')]
            [String]$marker = $null,
            [Parameter(ParameterSetName = 'auto')]
            [Switch]$autopage
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        If ($PSCmdlet.ParameterSetName -like "noauto")
        {
            $getwebhooks = $adminclient.WebhooksManager.GetWebhooksAsync($limit, $marker, $false)
        }
        Else
        {
            $getwebhooks = $adminclient.WebhooksManager.GetWebhooksAsync($limit, $marker, $true)
        }
        $getwebhooks.Wait()
        If ($getwebhooks.IsFaulted -eq $true)
        {
            Write-error $getwebhooks.Exception.InnerException
            return
        }
        Else
        {
            return $getwebhooks.Result
        }
        
    }
    
    function get-boxwebhook
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$webhookid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        $boxhook = $adminclient.WebhooksManager.GetWebhookAsync($webhookid)
        $boxhook.Wait()
        If ($boxhook.IsFaulted -eq $true)
        {
            Write-error $boxhook.Exception.InnerException
            return
        }
        Else
        {
            return $boxhook.Result
        }
        
    }
    
    function new-boxwebhook
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$targetid,
            [Parameter(Mandatory = $true)]
            [ValidateSet("file", "folder")]
            [String]$targettype,
            [Parameter(Mandatory = $true)]
            [ValidateSet("FILE.UPLOADED", "FILE.PREVIEWED", "FILE.DOWNLOADED", "FILE.TRASHED", "FILE.DELETED", "FILE.RESTORED", "FILE.COPIED", "FILE.MOVED", "FILE.LOCKED", "FILE.UNLOCKED", "FILE.RENAMED", "COMMENT.CREATED", "COMMENT.UPDATED", "COMMENT.DELETED", "TASK_ASSIGNMENT.CREATED", "TASK_ASSIGNMENT.UPDATED", "METADATA_INSTANCE.CREATED", "METADATA_INSTANCE.UPDATED", "METADATA_INSTANCE.DELETED", "FOLDER.CREATED", "FOLDER.RENAMED", "FOLDER.DOWNLOADED", "FOLDER.RESTORED", "FOLDER.DELETED", "FOLDER.COPIED", "FOLDER.MOVED", "FOLDER.TRASHED", "WEBHOOK.DELETED", "COLLABORATION.CREATED", "COLLABORATION.ACCEPTED", "COLLABORATION.REJECTED", "COLLABORATION.REMOVED", "COLLABORATION.UPDATED", "SHARED_LINK.DELETED", "SHARED_LINK.CREATED", "SHARED_LINK.UPDATED")]
            [System.String[]]$triggers,
            [Parameter(Mandatory = $true)]
            [String]$address
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        $webhookob = New-Object Box.V2.Models.BoxWebhookRequest
        $boxent = New-Object box.V2.Models.BoxRequestEntity
        $boxent.Id = $targetid
        $boxent.Type = $targettype
        $webhookob.Target = $boxent
        $webhookob.Triggers = $triggers
        $webhookob.Address = $address
        $createwebhook = $adminclient.WebhooksManager.CreateWebhookAsync($webhookob)
        $createwebhook.Wait()
        If ($createwebhook.IsFaulted -eq $true)
        {
            Write-error $createwebhook.Exception.InnerException
            return
        }
        Else
        {
            return $createwebhook.Result
        }
        
    }
    
    function remove-boxwebhook
    {
        param (
            [Parameter(Mandatory = $true)]
            [string]$webhookid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $deletewebhook = $adminclient.WebhooksManager.DeleteWebhookAsync($webhookid)
        $deletewebhook.Wait()
        If ($deletewebhook.IsFaulted -eq $true)
        {
            Write-error $deletewebhook.Exception.InnerException
            return
        }
        Else
        {
            return $deletewebhook.Result
        }
        
    }
    
    function set-boxwebhook
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$webhookid,
            [String]$targetid,
            [ValidateSet("file", "folder")]
            [String]$targettype,
            [ValidateSet("FILE.UPLOADED", "FILE.PREVIEWED", "FILE.DOWNLOADED", "FILE.TRASHED", "FILE.DELETED", "FILE.RESTORED", "FILE.COPIED", "FILE.MOVED", "FILE.LOCKED", "FILE.UNLOCKED", "FILE.RENAMED", "COMMENT.CREATED", "COMMENT.UPDATED", "COMMENT.DELETED", "TASK_ASSIGNMENT.CREATED", "TASK_ASSIGNMENT.UPDATED", "METADATA_INSTANCE.CREATED", "METADATA_INSTANCE.UPDATED", "METADATA_INSTANCE.DELETED", "FOLDER.CREATED", "FOLDER.RENAMED", "FOLDER.DOWNLOADED", "FOLDER.RESTORED", "FOLDER.DELETED", "FOLDER.COPIED", "FOLDER.MOVED", "FOLDER.TRASHED", "WEBHOOK.DELETED", "COLLABORATION.CREATED", "COLLABORATION.ACCEPTED", "COLLABORATION.REJECTED", "COLLABORATION.REMOVED", "COLLABORATION.UPDATED", "SHARED_LINK.DELETED", "SHARED_LINK.CREATED", "SHARED_LINK.UPDATED")]
            [System.String[]]$triggers,
            [String]$address
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $webhookob = New-Object Box.V2.Models.BoxWebhookRequest
        $webhookob.Id = $webhookid
        If (($PSBoundParameters.Keys -contains "targetid") -or ($PSBoundParameters.Keys -contains "targettype"))
        {
            $boxent = New-Object Box.V2.Models.BoxRequestEntity
            $boxent.Id = $targetid
            $boxent.Type = $targettype
            $webhookob.Target = $boxent
        }
        If ($PSBoundParameters.Keys -contains "triggers")
        {
            $webhookob.Triggers = $triggers
        }
        If ($PSBoundParameters.Keys -contains "address")
        {
            $webhookob.Address = $address
        }
        $updatewebhook = $adminclient.WebhooksManager.UpdateWebhookAsync($webhookob)
        $updatewebhook.Wait()
        If ($updatewebhook.IsFaulted -eq $true)
        {
            Write-error $updatewebhook.Exception.InnerException
            return
        }
        Else
        {
            return $updatewebhook.Result
        }
        
    }
    
    function get-boxtermsofservice
    {
        param (
            [ValidateSet("managed", "external")]
            [String]$tostype = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        $gettos = $adminclient.TermsOfServiceManager.GetTermsOfServicesAsync($tostype)
        $gettos.Wait()
        If ($gettos.IsFaulted -eq $true)
        {
            Write-error $gettos.Exception.InnerException
            return
        }
        Else
        {
            return $gettos.Result
        }
        
    }
    
    function get-boxtermsofservicebyid
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$tosid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        $gettosid = $adminclient.TermsOfServiceManager.GetTermsOfServicesByIdAsync($tosid)
        $gettosid.Wait()
        If ($gettosid.IsFaulted -eq $true)
        {
            Write-error $gettosid.Exception.InnerException
            return
        }
        Else
        {
            return $gettosid.Result
        }
        
    }
    
    function get-boxtermsofserviceuserstatuses
    {
        param (
            [Parameter(Mandatory = $true)]
            [string]$tosid,
            [string]$userid = $null
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        $gettosuser = $adminclient.TermsOfServiceManager.GetTermsOfServiceUserStatusesAsync($tosid, $userid)
        $gettosuser.Wait()
        If ($gettosuser.IsFaulted -eq $true)
        {
            Write-error $gettosuser.Exception.InnerException
            return
        }
        Else
        {
            return $gettosuser.Result
        }
        
    }
    
    function new-boxtermsofservice
    {
        param (
            [Parameter(Mandatory = $true)]
            [ValidateSet("enabled", "disabled")]
            [string]$status,
            [Parameter(Mandatory = $true)]
            [ValidateSet("managed", "external")]
            [String]$tostype,
            [Parameter(Mandatory = $true)]
            [String]$text
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        $tosreq = New-Object Box.V2.Models.BoxTermsOfServicesRequest
        $tosreq.Status = $status
        $tosreq.TosType = $tostype
        $tosreq.Text = $text
        $newboxtos = $adminclient.TermsOfServiceManager.CreateTermsOfServicesAsync($tosreq)
        $newboxtos.Wait()
        If ($newboxtos.IsFaulted -eq $true)
        {
            Write-error $newboxtos.Exception.InnerException
            return
        }
        Else
        {
            return $newboxtos.Result
        }
        
    }
    <#
    function new-boxtermsofserviceuserstatuses
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$tosid,
            [Parameter(Mandatory = $true)]
            [String]$userid,
            [switch]$accepted
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        $userob = New-Object box.V2.Models.BoxUser
        $userob.Id = $userid
        $tosob = New-Object Box.V2.Models.BoxTermsOfService
        $boxent = New-Object box.V2.Models.BoxEntity
        $boxent.
        $tosob.Id = $tosob
        $userstatreq = New-Object Box.V2.Models.BoxTermsOfServiceUserStatuses
        $userstatreq.TermsOfService
    }
    #>

    function set-boxtermsofservice
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$tosid,
            [ValidateSet("enabled", "disabled")]
            [string]$status,
            [ValidateSet("managed", "external")]
            [String]$tostype,
            [String]$text
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        $tosreq = New-Object box.V2.Models.BoxTermsOfServicesRequest
        $tosreq.Id = $tosid
        If ($PSBoundParameters.Keys -contains "status")
        {
            $tosreq.Status = $status
        }
        If ($PSBoundParameters.Keys -contains "tostype")
        {
            $tosreq.TosType = $tostype
        }
        if ($PSBoundParameters.Keys -contains "text")
        {
            $tosreq.Text = $text
        }
        $updatetos = $adminclient.TermsOfServiceManager.UpdateTermsOfServicesAsync($tosreq)
        $updatetos.Wait()
        If ($updatetos.IsFaulted -eq $true)
        {
            Write-error $updatetos.Exception.InnerException
            return
        }
        Else
        {
            return $updatetos.Result
        }
        
    }
    
    function new-boxtask
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$itemid,
            [Parameter(Mandatory = $true)]
            [ValidateSet("file", "discussion", "comment", "folder", "retention_policy", "enterprise", "user", "group", "web_link", "file_version", "metadata_template")]
            [String]$itemtype,
            [String]$message,
            [System.Nullable[DateTime]]$dueby
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        $boxent = New-Object box.V2.Models.BoxRequestEntity
        $boxent.Id = $itemid
        $boxent.Type = $itemtype
        $taskreq = New-Object box.V2.Models.BoxTaskCreateRequest
        $taskreq.Item = $boxent
        If ($PSBoundParameters.Keys -contains "message")
        {
            $taskreq.Message = $message
        }
        If ($PSBoundParameters.Keys -contains "dueby")
        {
            $taskreq.DueAt = $dueby
        }
        $newtask = $adminclient.TasksManager.CreateTaskAsync($taskreq)
        $newtask.Wait()
        If ($newtask.IsFaulted -eq $true)
        {
            Write-error $newtask.Exception.InnerException
            return
        }
        Else
        {
            return $newtask.Result
        }
        
    }
    
    function remove-boxtask
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$taskid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        $deletetask = $adminclient.TasksManager.DeleteTaskAsync($taskid)
        $deletetask.Wait()
        If ($deletetask.IsFaulted -eq $true)
        {
            Write-error $deletetask.Exception.InnerException
            return
        }
        Else
        {
            return $deletetask.Result
        }
        
    }
    
    function get-boxtask
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$taskid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        
        $gettask = $adminclient.TasksManager.GetTaskAsync($taskid)
        $gettask.Wait()
        If ($gettask.IsFaulted -eq $true)
        {
            Write-error $gettask.Exception.InnerException
            return
        }
        Else
        {
            return $gettask.Result
        }
        
    }
    
    function set-boxtask
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$taskid,
            [System.Nullable[DateTime]]$dueby,
            [String]$message
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        $updatereq = New-Object box.V2.Models.BoxTaskUpdateRequest
        $updatereq.Id = $taskid
        If ($PSBoundParameters.Keys -contains "dueby")
        {
            $updatereq.DueAt = $dueby
        }
        If ($PSBoundParameters.Keys -contains "message")
        {
            $updatereq.Message = $message
        }
        $updatetask = $adminclient.TasksManager.UpdateTaskAsync($updatereq)
        $updatetask.Wait()
        If ($updatetask.IsFaulted -eq $true)
        {
            Write-error $updatetask.Exception.InnerException
            return
        }
        Else
        {
            return $updatetask.Result
        }
        
    }
    
    function new-boxtaskassignment
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$taskid,
            [Parameter(Mandatory = $true)]
            [String]$assigntoid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        $taskreq = New-Object box.V2.Models.Request.BoxTaskRequest
        $taskreq.Id = $taskid
        $assignreq = New-Object box.V2.Models.Request.BoxAssignmentRequest
        $assignreq.Id = $assigntoid
        $taskassign = New-object Box.V2.Models.BoxTaskAssignmentRequest
        $taskassign.AssignTo = $assignreq
        $taskassign.Task = $taskreq
        $newtaskassign = $adminclient.TasksManager.CreateTaskAssignmentAsync($taskassign)
        $newtaskassign.Wait()
        If ($newtaskassign.IsFaulted -eq $true)
        {
            Write-error $newtaskassign.Exception.InnerException
            return
        }
        Else
        {
            return $newtaskassign.Result
        }
        
    }
    
    function get-allboxtaskassignments
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$taskid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        $getassign = $adminclient.TasksManager.GetAssignmentsAsync($taskid)
        $getassign.Wait()
        If ($getassign.IsFaulted -eq $true)
        {
            Write-error $getassign.Exception.InnerException
            return
        }
        Else
        {
            return $getassign.Result
        }
        
    }
    
    function get-boxtaskassignment
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$taskassignmentid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        $gettaskassignment = $adminclient.TasksManager.GetTaskAssignmentAsync($taskassignmentid)
        $gettaskassignment.Wait()
        If ($gettaskassignment.IsFaulted -eq $true)
        {
            Write-error $gettaskassignment.Exception.InnerException
            return
        }
        Else
        {
            return $gettaskassignment.Result
        }
        
    }
    
    function set-boxtaskassignment
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$taskassignid,
            [String]$message,
            [ValidateSet("completed", "incomplete", "approved", "rejected")]
            [String]$resolution
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        $upreq = New-Object box.V2.Models.BoxTaskAssignmentUpdateRequest
        $upreq.Id = $taskassignid
        If ($PSBoundParameters.Keys -contains "message")
        {
            $upreq.Message = $message
        }
        If ($PSBoundParameters.Keys -contains "resolution")
        {
            If ($resolution -like "completed")
            {
                $upreq.ResolutionState = [Box.V2.Models.ResolutionStateType]::completed
            }
            elseif ($resolution -like "incomplete")
            {
                $upreq.ResolutionState = [Box.V2.Models.ResolutionStateType]::incomplete
            }
            elseif ($resolution -like "approved")
            {
                $upreq.ResolutionState = [Box.V2.Models.ResolutionStateType]::approved
            }
            elseif ($resolution -like "rejected")
            {
                $upreq.ResolutionState = [Box.V2.Models.ResolutionStateType]::rejected
            }
            Else
            {
                Write-Error "Invalid input for resolution type."
                return
            }
        }
        $updateassign = $adminclient.TasksManager.UpdateTaskAssignmentAsync($upreq)
        $updateassign.Wait()
        If ($updateassign.IsFaulted -eq $true)
        {
            Write-error $updateassign.Exception.InnerException
            return
        }
        Else
        {
            return $updateassign.Result
        }
        
    }
    
    function remove-boxtaskassignment
    {
        param (
            [Parameter(Mandatory = $true)]
            [String]$taskassignmentid
        )
        If ($adminclient -eq $null)
        {
            Write-error "You have not authenticated to box yet. Run `"connect-box`" to authenticate to box. If you have not preparred your box environment or local machine to use the poshbox module, please read the instructions at https://github.com/whiggs/PoshBox for information on how to do so and obtain the authentication file you will need."
            return
        }
        $removeassign = $adminclient.TasksManager.DeleteTaskAssignmentAsync($taskassignmentid)
        $removeassign.Wait()
        If ($removeassign.IsFaulted -eq $true)
        {
            Write-error $removeassign.Exception.InnerException
            return
        }
        Else
        {
            return $removeassign.Result
        }
        
    }
    
    Export-ModuleMember -Function connect-box, get-boxusers, set-boxuserlogin, new-boxuser, remove-boxuser, new-boxemailalias, transfer-boxusercontent, upload-boxfile, Get-boxemailalias, Get-boxuserinfo, Get-boxuserinvite, invite-usertobox, remove-boxemailalias, set-boxuser, new-boxfolder, get-boxfolderitems, new-boxfoldersharelink, copy-boxfolder, remove-boxfolder, remove-boxfoldersharedlink, get-boxfolderinfo, get-boxfoldercollaborations, Get-boxtrashedfolderitems, get-trashedboxfolder, remove-boxtrashfolder, restore-trashedboxfolder, set-boxfolderinfo, get-boxcollections, Get-boxcollectionitems, addremove-boxcollectionsforfolder, addremove-boxcollectionsforfile, get-boxfileinfo, new-boxcomment, remove-boxcomment, get-boxfilecomment, Get-boxcommentinfo, set-boxcomment, get-boxenterpriseevents, get-boxuserevents, copy-boxfile, upload-boxfilenewversion, remove-boxfile, get-boxfileversions, remove-boxoldfileversion, new-boxfilesharelink, remove-boxfilesharelink, new-boxcollaborator, Get-boxcollaborationinfo, get-pendingboxcollaboration, remove-boxcollaboration, get-boxfilecollaborations, get-boxfiledownloaduri, get-boxfiletasks, lock-boxfile, get-boxfilelock, get-boxfilepreview, get-boxfilethumbnail, get-trashedboxfile, set-boxfileversion, remove-boxtrashfile, restore-boxtrashfile, unlock-boxfile, set-boxfileinfo, get-allboxgroups, new-boxgroup, remove-boxgroup, get-boxgroup, get-boxgroupmembershipforgroup, get-boxgroupmembershipforuser, add-boxgroupmember, remove-boxgroupmembership, get-boxgroupmembership, set-boxgroup, set-boxgroupmembership, new-boxlegalholdpolicy, new-boxlegalholdpolicyassignment, remove-boxlegalholdpolicy, remove-boxlegalholdpolicyassignment, get-boxlegalholdpolicyassignment, get-boxlegalholdpolicy, get-allboxlegalholdpolicies, get-allboxlegalholdpolicyassignments, get-allboxfileversionlegalholds, get-boxfileversionlegalhold, set-boxlegalholdpolicy, get-allboxMetadataCascadePolicies, get-boxmetadataCascadePolicy, new-boxmetadatacascadepolicy, remove-boxmetadatacascadepolicy, apply-boxmetadatacascadepolicy, get-allboxfoldermetadatatemplates, get-allboxfilemetadatatemplates, get-boxrecentitems, find-boxitem, get-boxshareditembyurl, get-allboxwebhooks, get-boxwebhook, new-boxwebhook, remove-boxwebhook, set-boxwebhook, get-boxtermsofservice, get-boxtermsofservicebyid, get-boxtermsofserviceuserstatuses, new-boxtermsofservice, set-boxtermsofservice, new-boxtask, remove-boxtask, get-boxtask, set-boxtask, new-boxtaskassignment, get-allboxtaskassignments, get-boxtaskassignment, set-boxtaskassignment, remove-boxtaskassignment