poshbox.psm1
<#
.NOTES -------------------------------------------------------------------------------- Code generated by: SAPIEN Technologies, Inc., PowerShell Studio 2019 v5.6.157 Generated on: 2/5/2019 3:40 PM 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)] [ValidatePattern('^([a-zA-Z]:\\|\\\\)(((?![<>:"/\\|?*]).)+((?<![ .])\\)?)*\.json$')] [ValidateScript({ Test-Path $_ -PathType Leaf })] [String]$path, [ValidatePattern("\d{4,}")] [string]$id ) If ($path) { 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 (($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" } $boxconfig = New-Object -TypeName Box.v2.Config.Boxconfig -Argumentlist $boxob.clientid, $boxob.clientsecret, $boxob.enterpriseid, $boxob.privatekey, $boxob.passphrase, $boxob.publickeyid $boxJWT = New-Object -TypeName Box.V2.JWTAuth.BoxJWTAuth -Argumentlist $boxconfig $global:tokenreal = $boxJWT.AdminToken If (-not $id) { $global:adminclient = $boxjwt.AdminClient($tokenreal) } Else { $global:adminclient = $boxjwt.AdminClient($tokenreal, $id) } #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 ($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 ) $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 (($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 ) $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 ($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 ($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 (!(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 ) $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 ) $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 ) $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 ) 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 ) $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 ) $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 ) #$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 ($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 ) $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 ) $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 ($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 ) $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 ) $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 ) $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 ) $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 ($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 ) $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 ) $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 ($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 ) $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 { $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 ($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 ) $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 ) $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 ) $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 ) $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 ) $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 ) $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 ) $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 ) 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 ($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 ($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 (!(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 ) $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 ) $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 ) $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 ) $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 ) $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 ) $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 ) $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 ) $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 ) $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 ) $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 ) $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 ) $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 ) $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 ) $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 ) $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 ($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 ) $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 ) $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 ) $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 ) $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 ) $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 ) $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 ($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 ) $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 ) $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 ) $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 ($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 ($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 ) $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-boxgroupmember { param ( [Parameter(Mandatory = $true)] [string]$groupid ) $removemember = $adminclient.GroupsManager.DeleteGroupMembershipAsync($groupid) $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 ) $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 ) $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 ) $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 ) $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", "discussion", "comment", "folder", "retention_policy", "enterprise", "user", "group", "web_link", "file_version", "metadata_template")] [String]$assigntotype ) $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 ) $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 ) $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 ) $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 ) $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 ($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 ($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 ($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 ) $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 ) $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, [System.String[]]$fields = $null ) } 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-boxgroupmember, 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 |