poshbox.psm1
<#
.NOTES -------------------------------------------------------------------------------- Code generated by: SAPIEN Technologies, Inc., PowerShell Studio 2019 v5.6.156 Generated on: 1/10/2019 8:34 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)] [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 ( [Parameter()] [string]$SearchString, [Parameter(Mandatory = $true, ParameterSetName = "noautopage")] [ValidateRange(1, 1000)] [int]$limit, [Parameter(Mandatory = $true, ParameterSetName = "noautopage")] [int]$offset, [Parameter()] [String[]]$fields, [String]$usertype, [String]$externalappuserid, [Parameter(ParameterSetName = 'autopage')] [Switch]$autopaginate ) If ($PSCmdlet.ParameterSetName -like "autopage") { $usertask = $adminclient.UsersManager.GetEnterpriseUsersAsync($PSBoundParameters.SearchString, 0, 1000, $PSBoundParameters.fields, $PSBoundParameters.usertype, $PSBoundParameters.externalappuserid, $true) } Else { $usertask = $adminclient.UsersManager.GetEnterpriseUsersAsync($PSBoundParameters.SearchString, $PSBoundParameters.offset, $PSBoundParameters.limit, $PSBoundParameters.fields, $PSBoundParameters.usertype, $PSBoundParameters.externalappuserid, $false) } $usertask.Wait() If ($usertask.IsFaulted -eq $true) { Write-error $usertask.Exception.InnerException return } else { $psob = New-Object -TypeName System.Management.Automation.PSObject $psob | Add-Member -MemberType NoteProperty -Name "entries" -Value $usertask.Result.Entries $psob | Add-Member -MemberType NoteProperty -Name "TotalCount" -Value $usertask.Result.TotalCount return $psob } } function set-boxuserlogin { param ( [parameter(Mandatory = $true)] [System.String]$id, [parameter(Mandatory = $true)] [string]$newlogin, [Parameter()] [String[]]$userinfo ) $change = $adminclient.UsersManager.ChangeUsersLoginAsync($id, $newlogin, $PSBoundParameters.userinfo) $change.wait() If ($change.IsFaulted -eq $true) { $result = $change.Exception.InnerException } Else { $result = $change.Status } return $result } function new-boxuser { param ( [parameter(Mandatory = $true)] [hashtable]$userdetails, [String[]]$userinfo ) 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, $PSBoundParameters.userinfo) $newuser.Wait() If ($newuser.IsFaulted -eq $true) { Write-error $newuser.Exception.InnerException return } Else { return $newuser.Result } } } function add-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) { Return $delete.Exception.InnerException } Else { return $delete.Status } } 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, [Parameter(Mandatory = $true)] [system.TimeSpan]$time ) 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, $PSBoundParameters.fields, $PSBoundParameters.time) $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.Entries } } 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 ) 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 If ($PSBoundParameters.Keys -notcontains "fields") { $invreq = $adminclient.UsersManager.InviteUserToEnterpriseAsync($inviteob) } Else { $invreq = $adminclient.UsersManager.InviteUserToEnterpriseAsync($inviteob, $fields) } $invreq.Wait() If ($invreq.IsFaulted -eq $true) { Write-error $invreq.Exception.InnerException return } Else { $psob = New-Object -TypeName System.Management.Automation.PSObject $psob | Add-Member -MemberType NoteProperty -Name "InvitedUser" -Value $invreq.Result.ActionableBy $psob | Add-Member -MemberType NoteProperty -Name "invitedto" -Value $invreq .Result.invitedto $psob | Add-Member -MemberType NoteProperty -Name "status" -Value $invreq .Result.status $psob | Add-Member -MemberType NoteProperty -Name "id" -Value $invreq .Result.id return $psob } } function Get-boxuserinvite { param ( [Parameter(Mandatory = $true)] [String]$inviteid, [System.String[]]$fields ) If ($PSBoundParameters.Keys -notcontains "fields") { $invitereq = $adminclient.UsersManager.GetUserInviteAsync($inviteid) } Else { $invitereq = $adminclient.UsersManager.GetUserInviteAsync($inviteid, $fields) } $invitereq.Wait() If ($invitereq.IsFaulted -eq $true) { Write-error $invitereq.Exception.InnerException return } Else { $psob = New-Object -TypeName System.Management.Automation.PSObject $psob | Add-Member -MemberType NoteProperty -Name "InvitedUser" -Value $invitereq.Result.ActionableBy $psob | Add-Member -MemberType NoteProperty -Name "invitedto" -Value $invitereq.Result.invitedto $psob | Add-Member -MemberType NoteProperty -Name "status" -Value $invitereq.Result.status $psob | Add-Member -MemberType NoteProperty -Name "id" -Value $invitereq.Result.id return $psob } } function set-boxuser { param ( [Parameter(Mandatory = $true)] [hashtable]$updateinfo, [System.String[]]$fields ) $boxuserreq = New-Object Box.V2.Models.BoxUserRequest -Property $updateinfo If ($PSBoundParameters.Keys -notcontains "fields") { $userupdate = $adminclient.UsersManager.UpdateUserInformationAsync($boxuserreq) } Else { $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)] [hashtable]$foldreq, [string[]]$fields ) $folderreq = New-Object Box.V2.Models.BoxFolderRequest -Property $foldreq If ($PSBoundParameters.Keys -notcontains "fields") { $boxfolreq = $adminclient.FoldersManager.CreateAsync($folderreq) } Else { $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 ) If ($PSCmdlet.ParameterSetName -like "auto") { $foldlist = $adminclient.FoldersManager.GetFolderItemsAsync($folderid, 1000, 0, $PSBoundParameters.fields, $true) } Else { $foldlist = $adminclient.FoldersManager.GetFolderItemsAsync($folderid, $limit, $offset, $PSBoundParameters.fields, $false) } $foldlist.Wait() If ($foldlist.IsFaulted -eq $true) { Write-error $foldlist.Exception.InnerException return } Else { $psob = New-Object -TypeName System.Management.Automation.PSObject $psob | Add-Member -MemberType NoteProperty -Name "totalcount" -Value $foldlist.Result.TotalCount $psob | Add-Member -MemberType NoteProperty -Name "Entries" -Value $foldlist.Result.Entries return $psob } } function new-boxfoldersharelink { param ( [Parameter(Mandatory = $true)] [String]$foldid, [ValidateSet("open", "collaborators", "company")] [System.String]$accesstype = "open", [String]$password, [System.String[]]$fields ) $sharelink = [Box.V2.Models.BoxSharedLinkRequest]::new() $sharelink.Access = $accesstype If ($PSBoundParameters.Keys -contains "password") { $sharelink.Password = $password } If ($PSBoundParameters.Keys -notcontains "fields") { $sharelinkreq = $adminclient.FoldersManager.CreateSharedLinkAsync($foldid, $sharelink) } Else { $sharelinkreq = $adminclient.FoldersManager.CreateSharedLinkAsync($foldid, $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 ) $folreq = @{ id = "$folderid" parent = @{ id = "$parentfolderid" } } If ($PSBoundParameters.Keys -notcontains "fields") { $proc = $adminclient.FoldersManager.CopyAsync($folreq) } Else { $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) } $folddelete.Wait() If ($folddelete.IsFaulted -eq $true) { Write-error $folddelete.Exception.InnerException return } Else { return $folddelete.Status } } function copy-boxfile { param ( [Parameter(Mandatory = $true)] [System.String]$fileid, [Parameter(Mandatory = $true)] [String]$parentfolderid, [System.String[]]$fields ) $copyreq = @{ id = "$fileid" parent = @{ id = "$parentfolderid" } } If ($PSBoundParameters.Keys -notcontains "fields") { $copyfile = $adminclient.FilesManager.CopyAsync($copyreq) } Else { $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]$sharedlinkid ) $delshare = $adminclient.FoldersManager.DeleteSharedLinkAsync($sharedlinkid) $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 ) If ($PSBoundParameters.Keys -notcontains "fields") { $folinfo = $adminclient.FoldersManager.GetInformationAsync($folderid) } Else { $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]$foldid, [System.String[]]$fields ) If ($PSBoundParameters.Keys -notcontains "fields") { $foldcollab = $adminclient.FoldersManager.GetCollaborationsAsync($foldid) } Else { $foldcollab = $adminclient.FoldersManager.GetCollaborationsAsync($foldid, $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", Mandatory = $true)] [int]$limit, [Parameter(ParameterSetName = 'noautopage', Mandatory = $true)] [int]$offset, [System.String[]]$fields ) If ($PSCmdlet.ParameterSetName -like "autopage") { $trasheditems = $adminclient.FoldersManager.GetTrashItemsAsync(1000, 0, $PSBoundParameters.fields, $true) } Else { $trasheditems = $adminclient.FoldersManager.GetTrashItemsAsync($PSBoundParameters.limit, $PSBoundParameters.offset, $PSBoundParameters.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]$foldid, [System.String[]]$fields ) If ($PSBoundParameters.Keys -notcontains "fields") { $trashfold = $adminclient.FoldersManager.GetTrashedFolderAsync($foldid) } Else { $trashfold = $adminclient.FoldersManager.GetTrashedFolderAsync($foldid, $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]$foldid ) $purgefold = $adminclient.FoldersManager.PurgeTrashedFolderAsync($foldid) $purgefold.Wait() If ($purgefold.IsFaulted -eq $true) { Write-error $purgefold.Exception.InnerException return } Else { return $purgefold.Status } } function restore-trashedboxfolder { param ( [Parameter(Mandatory = $true)] [String]$trashedfolderid, [Parameter(Mandatory = $true)] [String]$restoretofolderid, [System.String[]]$fields ) $foldreq = @{ id = "$trashedfolderid" parent = @{ id = "$restoretofolderid" } } If ($PSBoundParameters.Keys -notcontains "fields") { $restorefold = $adminclient.FoldersManager.RestoreTrashedFolderAsync($foldreq) } Else { $restorefold = $adminclient.FoldersManager.RestoreTrashedFolderAsync($foldreq, $fields) } $restorefold.Wait() If ($restorefold.IsFaulted -eq $true) { Write-error $restorefold.Exception.InnerException return } Else { return $restorefold.Result } } function update-boxfolderinfo { param ( [Parameter(Mandatory = $true)] [Box.V2.Models.BoxFolderRequest]$updateinfo, [System.String[]]$fields ) If ($PSBoundParameters.Keys -notcontains "fields") { $folderupdate = $adminclient.FoldersManager.UpdateInformationAsync($updateinfo) } Else { $folderupdate = $adminclient.FoldersManager.UpdateInformationAsync($updateinfo, $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 ) If ($PSCmdlet.ParameterSetName -like "noauto") { $boxcollections = $adminclient.CollectionsManager.GetCollectionItemsAsync($collectionid, $limit, $offset, $PSBoundParameters.fields, $false) } Else { $boxcollections = $adminclient.CollectionsManager.GetCollectionItemsAsync($collectionid, 1000, 0, $PSBoundParameters.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 ) If ($PSBoundParameters.Keys -notcontains "fields") { $fileinfo = $adminclient.FilesManager.GetInformationAsync($fileid) } Else { $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", "folder", "retention_policy", "enterprise", "user", "group", "web_link", "file_version", "metadata_template")] [String]$boxtype, [Parameter(Mandatory = $true)] [String]$entityid, [Parameter(Mandatory = $true)] [String]$comment, [System.String[]]$fields ) $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 If ($PSBoundParameters.Keys -notcontains "fields") { $createcomment = $adminclient.CommentsManager.AddCommentAsync($commreq) } else { $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.Status } } function get-boxfilecomment { param ( [Parameter(Mandatory = $true)] [String]$fileid, [System.String[]]$fields ) If ($PSBoundParameters.Keys -notcontains "fields") { $filecomments = $adminclient.FilesManager.GetCommentsAsync($fileid) } Else { $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 ) If ($PSBoundParameters.Keys -notcontains "fields") { $commentinfo = $adminclient.CommentsManager.GetInformationAsync($commentid) } Else { $commentinfo = $adminclient.CommentsManager.GetInformationAsync($commentid, $fields) } $commentinfo.Wait() If ($commentinfo.IsFaulted -eq $true) { Write-error $commentinfo.Exception.InnerException return } Else { return $commentinfo.Result } } function update-boxcomment { param ( [Parameter(Mandatory = $true)] [String]$commentid, [Parameter(Mandatory = $true)] [ValidateSet("file", "discussion", "comment", "folder", "retention_policy", "enterprise", "user", "group", "web_link", "file_version", "metadata_template")] [String]$boxtype, [Parameter(Mandatory = $true)] [String]$entityid, [Parameter(Mandatory = $true)] [String]$comment, [System.String[]]$fields ) Try { $commenttest = Get-boxcommentinfo -commentid $commentid -ErrorAction Stop } Catch { Write-Error "The id is not associated with a valid comment." 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 If ($PSBoundParameters.Keys -notcontains "fields") { $updatecomment = $adminclient.CommentsManager.AddCommentAsync($commentid, $commreq) } else { $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 = $null, [datetime]$createdafter = $null ) $getboxevents = $adminclient.EventsManager.EnterpriseEventsAsync($limit, $offset, $eventtypes, $createdafter, $createdbefore) $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 copy-boxfile { param ( [Parameter(Mandatory = $true)] [String]$fileid, [Parameter(Mandatory = $true)] [String]$parentfoldid, [System.String[]]$fields ) $filereq = @{ id = "$fileid" parent = @{ id = "$parentfoldid" } } If ($PSBoundParameters.Keys -notcontains "fields") { $filecopy = $adminclient.FilesManager.CopyAsync($filereq) } Else { $filecopy = $adminclient.FilesManager.CopyAsync($filereq, $fields) } $filecopy.Wait() If ($filecopy.IsFaulted -eq $true) { Write-error $filecopy.Exception.InnerException return } Else { return $filecopy.Result } } function upload-boxfilenewversion { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [String]$filename, [Parameter(Mandatory = $true)] [String]$fileid, [Parameter(Mandatory = $true)] [String]$path, [String[]]$fields, [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, $PSBoundParameters.fields, $timespan, $null, $true, $null) $fileversionup.Wait() If ($fileversionup.IsFaulted -eq $true) { Write-error $fileversionup.Exception.InnerException return } Else { return $fileversionup.Result } } function new-boxfilesharedlink { param ( [Parameter(Mandatory = $true)] [String]$fileid, [ValidateSet("open", "collaborators", "company")] [String]$accesstype = "open", [String]$password, [System.String[]]$fields ) $sharelink = [Box.V2.Models.BoxSharedLinkRequest]::new() $sharelink.Access = $accesstype If ($PSBoundParameters.Keys -contains "password") { $sharelink.Password = $password } If ($PSBoundParameters.Keys -notcontains "fields") { $sharelinkreq = $adminclient.FoldersManager.CreateSharedLinkAsync($foldid, $sharelink) } Else { $sharelinkreq = $adminclient.FoldersManager.CreateSharedLinkAsync($foldid, $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.Status } } Export-ModuleMember -Function connect-box, get-boxusers, set-boxuserlogin, new-boxuser, remove-boxuser, add-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, copy-boxfile, remove-boxfoldersharedlink, get-boxuserinfo, new-boxfoldersharelink, get-boxfolderinfo, get-boxfoldercollaborations, Get-boxtrashedfolderitems, get-trashedboxfolder, remove-boxtrashfolder, restore-trashedboxfolder, update-boxfolderinfo, get-boxcollections, Get-boxcollectionitems, addremove-boxcollectionsforfolder, addremove-boxcollectionsforfile, get-boxfileinfo, new-boxcomment, remove-boxcomment, get-boxfilecomment, Get-boxcommentinfo, update-boxcomment, get-boxenterpriseevents, get-boxuserevents, copy-boxfile, upload-boxfilenewversion, remove-boxfile |