PSBoxCLIFunctions.psm1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 |
Function Get-BoxUser{ Param ([string]$email,[string]$userID) if ($email) { $user = box users --filter=$email --json | ConvertFrom-Json if ($user) { write-host "Found Box user matching email address $email" return $user } else { write-host "Error: User with email address $email was not found in Box" -ForegroundColor Red exit } } if ($userID) { $user = box users:get $userID --json | ConvertFrom-Json if ($user) { write-host "Found Box user matching userID $userID" return $user } else { write-host "Error: User with userID $userID was not found in Box" -ForegroundColor Red exit } } <# .SYNOPSIS Gets the Box User details from an email address or UserID. .DESCRIPTION Gets the Box User details from an email address or UserID using Box CLI. Get the user directly using User ID, or search using their email address. Returns an object with all the Box user details. .PARAMETER email Specifies the users email address .PARAMETER userID Specifies the users Box ID .INPUTS Email address, Box UserID .OUTPUTS Object containing details of the Box user. Properties: type id name login created_at modified_at language timezone space_amount space_used max_upload_size status job_title phone address avatar_url notification_email .EXAMPLE PS> Get-BoxUser -email "user@domain.com" .EXAMPLE PS> Get-BoxUser -userID "11111" #> } Function Get-BoxAllUsers{ box users --filter= --json | ConvertFrom-Json <# .SYNOPSIS Gets all Box users. .DESCRIPTION Gets all Box users. .INPUTS None .OUTPUTS Array containing all Box users. Properties: id name login created_at modified_at language timezone space_amount space_used max_upload_size status job_title .EXAMPLE PS> Get-BoxUsers | ft .EXAMPLE PS> $users = Get-BoxUsers $users | ft #> } Function Get-BoxGroup{ Param ([string]$groupID) $group = box groups:get $groupID --json | ConvertFrom-Json if ($group) { write-host "Found Box group $groupID" return $group } else { write-host "Error: Group with ID $groupID was not found in Box" -ForegroundColor Red exit } <# .SYNOPSIS Gets the Box Group details from a group ID. .DESCRIPTION Gets the Box Group details from a group ID using Box CLI. Use Get-BoxGroups to get all box groups and find the ID first. .PARAMETER groupID Specifies the group ID .INPUTS groupID .OUTPUTS Object containing details of the Box group. .EXAMPLE PS> Get-BoxGroup -groupID "11111" #> } Function Get-BoxGroups{ $groups = box groups --json | ConvertFrom-Json if ($groups) { return $groups } else { write-host "Error: No groups found" -ForegroundColor Red exit } <# .SYNOPSIS Gets all Box Groups .DESCRIPTION Gets all Box Group using Box CLI. There are no input parameters. .OUTPUTS Object containing details of all Box groups. .EXAMPLE PS> Get-BoxGroups #> } Function Add-BoxGroupMember{ Param ([string]$userID,[string]$groupID) box groups:memberships:add $userID $groupID --json | ConvertFrom-Json <# .SYNOPSIS Adds a user to a group .DESCRIPTION Adds a user to a group Requires userid ad groupid .PARAMETER userID Specifies the Box user ID .PARAMETER groupID Specifies the Box group ID .INPUTS groupID .INPUTS userID .OUTPUTS Object containing details of the Box group. .EXAMPLE PS> Add-BoxGroupMember -userID "11111" -groupID "22222" #> } Function Get-BoxGroupMember{ Param ([string]$groupID) $users = box groups:memberships $groupID --json | ConvertFrom-Json if (!$users) {write-host "No group members found"} else {return $users} <# .SYNOPSIS Gets the members of a Box group .DESCRIPTION Gets the members of a Box group using the BoxCLI .PARAMETER groupID Specifies the Box group ID .INPUTS groupID .OUTPUTS Object containing details of the Box group members. .EXAMPLE PS> Get-BoxGroupMember -groupID "11111" #> } Function Remove-BoxGroupMember{ Param ([string]$membershipID) box groups:memberships:remove $membershipID --json | ConvertFrom-Json <# .SYNOPSIS Removes a user from a group .DESCRIPTION Removes a user from a group Requires the membership ID, suggest to get this when you add the user to the group .PARAMETER membershipID Specifies the ID of the group membership .INPUTS membershipID .OUTPUTS .EXAMPLE PS> $addgroup = Add-BoxGroupMember -userID $boxuser.id -GroupID "5736585174" PS> Remove-BoxGroupMember -membershipID $addgroup.id #> } Function Get-BoxFolder{ Param ([Parameter(Mandatory=$true)][string]$folderID,[string]$asuserID) if ($asuserID) { $folder = box folders:get $folderID --as-user=$asuserID --json | ConvertFrom-Json } else { $folder = box folders:get $folderID --json | ConvertFrom-Json } if ($folder) { write-host "Found Box folder $folderID" return $folder } else { write-host "Error: The Box folder $folderID was not found" -ForegroundColor Red } <# .SYNOPSIS Gets a Box folder info from the ID using Box CLI. .DESCRIPTION Gets a Box folder info from the ID using Box CLI. Requires the Box folder ID and the optionally the asuserID as inputs. .PARAMETER folderID Specifies the Box folder ID (mandatory). .PARAMETER asuserID Specifies the Box user ID (optional). .INPUTS Box Folder ID, Box As-User ID. .OUTPUTS Returns an arrary containg the Box folder info. .EXAMPLE PS> Get-BoxFolder -folderID "11111" -asuserID "22222" #> } Function Remove-BoxFolderSharingLink{ Param ([Parameter(Mandatory=$true)][string]$folderID,[string]$asuserID) if ($asuserID) { $folder = box folders:unshare $folderID --as-user=$asuserID --json | ConvertFrom-Json } else { $folder = box folders:unshare $folderID --json | ConvertFrom-Json } <# .SYNOPSIS Removes a sharing link from a Box folder. .DESCRIPTION Removes a sharing link from a Box folder. Requires the Box folder ID and optionally the AsUserID .PARAMETER folderID Specifies the Box folder ID (mandatory). .PARAMETER asuserID Specifies the Box as-user ID (optional). .INPUTS Box Folder ID, Box As-User ID. .OUTPUTS None .EXAMPLE PS> Remove-BoxFolderSharingLink -folderID "11111" -asuserID "22222" #> } Function Remove-BoxFileSharingLink{ Param ([Parameter(Mandatory=$true)][string]$fileID,[string]$asuserID) if ($asuserID) { $file = box files:unshare $fileID --as-user=$asuserID --json | ConvertFrom-Json } else { $file = box files:unshare $fileID --json | ConvertFrom-Json } <# .SYNOPSIS Removes a sharing link from a Box file. .DESCRIPTION Removes a sharing link from a Box file. Requires the Box folder ID. .PARAMETER folderID Specifies the Box file ID (mandatory). .PARAMETER asuserID Specifies the Box as-user ID (optional). .INPUTS Box file ID, Box As-User ID. .OUTPUTS None .EXAMPLE PS> Remove-BoxFileSharingLink -folderID "11111" -asuserID "22222" #> } Function Get-BoxFolderContents{ Param ([Parameter(Mandatory=$true)][string]$folderID,[string]$asuserID) if ($asuserID) { box folders:items $folderID --as-user $asuserID --json | ConvertFrom-Json } else { box folders:items $folderID --json | ConvertFrom-Json } <# .SYNOPSIS Gets the contents of a Box folder from the folder ID using Box CLI. .DESCRIPTION Gets the contents of a Box folder from the ID using Box CLI. .PARAMETER folderID Specifies the Box folder ID (mandatory). .PARAMETER asuserID Specifies the Box as-user ID (optional). .INPUTS Box Folder ID .OUTPUTS Returns an arrary containg the Box folder contents .EXAMPLE PS> Get-BoxFolderContents -folderID "11111" .EXAMPLE PS> Get-BoxFolderContents -folderID "11111" -asuserID "22222" #> } Function New-BoxFolder{ Param ([Parameter(Mandatory=$true)][string]$parentID,[Parameter(Mandatory=$true)][string]$Name) box folders:create $parentID $Name --json | ConvertFrom-Json <# .SYNOPSIS Creates a new Box folder using parent folder ID and Name .DESCRIPTION Creates a new Box folder using parent folder ID and Name .PARAMETER parentID Specifies the parent Box folder ID (mandatory). .PARAMETER Name Specifies the name of the folder to create .INPUTS Parent Folder ID, Name .OUTPUTS Returns an arrary containg the Box folder info. .EXAMPLE PS> New-BoxFolder -parentID "11111" -Name "New folder" #> } Function Remove-BoxShare{ Param ([Parameter(Mandatory=$true)][string]$folderID,[string]$asuserID) if ($asuserID) { box folders:unshare $folderID --as-user=$asuserID --json | ConvertFrom-Json } else { box folders:unshare $folderID --json | ConvertFrom-Json } <# .SYNOPSIS Removes any shared links for a folder. .DESCRIPTION Removes any shared links for a folder. Requires the Box folder ID and the user ID as inputs. .PARAMETER folderID Specifies the Box folder ID (mandatory). .PARAMETER asuserID Specifies the Box user ID. 0 is the default (current user) (optional). .INPUTS Box Folder ID, Box As-User ID. .OUTPUTS None .EXAMPLE PS> Remove-BoxShare -folderID "11111" -asuserID "22222" #> } Function Get-BoxFolderCollaborations{ Param ([Parameter(Mandatory=$true)][string]$folderID,[string]$asuserID) if ($asuserID) { $folder = box folders:collaborations $folderID --as-user=$asuserID --json | ConvertFrom-Json } else { $folder = box folders:collaborations $folderID --json | ConvertFrom-Json } if ($folder) { return $folder } else { write-host "Error: No collaborations were found on folder $folderID" -ForegroundColor Red #exit } <# .SYNOPSIS Gets the collaborations on a Box folder info from the ID using Box CLI. .DESCRIPTION Gets the collaborations on a Box folder info from the ID using Box CLI. Requires the Box folder ID, optionally as-user. .PARAMETER folderID Specifies the Box folder ID (mandatory). .PARAMETER asuserID Specifies the Box user ID. 0 is the default (current user) (optional). .INPUTS Box Folder ID, Box As-User ID. .OUTPUTS Returns an arrary containg the Box folder collaborations .EXAMPLE PS> Get-BoxFolderCollaborations -folderID "11111" -asuserID "22222" .EXAMPLE PS> Get-BoxFolderCollaborations -folderID "11111" -asuserID "22222" | Where-Object {$_.accessible_by -like "*user@domain.com*"} #> } Function Add-BoxCollaboration{ Param ([Parameter(Mandatory=$true)][string]$folderID,[Parameter(Mandatory=$true)][string]$role,$userID,$groupID,$asuserID) if ($userID) { if ($asuserID) { box folders:collaborations:add $folderID --role $role --user-id $userID --as-user $asuserID } else { box folders:collaborations:add $folderID --role $role --user-id $userID } } elseif ($groupID) { if ($asuserID) { box folders:collaborations:add $folderID --role $role --group-id $groupID --as-user $asuserID } else { box folders:collaborations:add $folderID --role $role --group-id $groupID } } } Function Get-BoxFileCollaborations{ Param ([Parameter(Mandatory=$true)][string]$fileID,[string]$asuserID) if ($asuserID) { $file = box files:collaborations $fileID --as-user=$asuserID --json | ConvertFrom-Json } else { $file = box files:collaborations $fileID --json | ConvertFrom-Json } if ($file) { return $file } else { write-host "Error: The Box file $fileID was not found" -ForegroundColor Red exit } <# .SYNOPSIS Gets the collaborations on a Box file info from the ID using Box CLI. .DESCRIPTION Gets the collaborations on a Box file info from the ID using Box CLI. Requires the Box folder ID, optionally as-user. .PARAMETER folderID Specifies the Box file ID (mandatory). .PARAMETER asuserID Specifies the Box user ID. 0 is the default (current user) (optional). .INPUTS Box file ID, Box As-User ID. .OUTPUTS Returns an arrary containg the Box file collaborations .EXAMPLE PS> Get-BoxFileCollaborations -folderID "11111" -asuserID "22222" .EXAMPLE PS> Get-BoxFileCollaborations -folderID "11111" -asuserID "22222" | Where-Object {$_.accessible_by -like "*user@domain.com*"} #> } Function Add-BoxCollaboration{ Param ([Parameter(Mandatory=$true)][string]$folderID,[Parameter(Mandatory=$true)][string]$role,$userID,$groupID,$asuserID) if ($userID) { if ($asuserID) { box folders:collaborations:add $folderID --role $role --user-id $userID --as-user $asuserID } else { box folders:collaborations:add $folderID --role $role --user-id $userID } } elseif ($groupID) { if ($asuserID) { box folders:collaborations:add $folderID --role $role --group-id $groupID --as-user $asuserID } else { box folders:collaborations:add $folderID --role $role --group-id $groupID } } <# .SYNOPSIS Adds a user or group to be a collaborator on a Box folder. .DESCRIPTION Adds a user or group to be a collaborator on a Box folder. Specify target folder, role, userid or groupid to add, and as-user id with existing access. .PARAMETER folderID Specifies the Box folder ID (mandatory). .PARAMETER role The role to assign to the collaborator (mandatory). Valid values are: editor|viewer|previewer|uploader|previewer_uploader|viewer_uploader|co-owner .PARAMETER userID Specifies the Box user ID to add as a collaborator (mandatory). .PARAMETER asuserID Specifies the as-user Box user ID. 0 is the default (current user) (optional). .OUTPUTS Returns an arrary containg the Box folder info. .EXAMPLE PS> Add-BoxCollaboration -folderID "11111" -role "viewer" -userID "22222" -asuserID "33333" .EXAMPLE PS> Add-BoxCollaboration -folderID "11111" -role "co-owner" -groupID "44444" -asuserID "33333" #> } Function Move-BoxFolder{ Param ([Parameter(Mandatory=$true)][string]$folderID,[Parameter(Mandatory=$true)][string]$parentID,$asuserID) box folders:move $folderID $parentID --as-user $asuserID <# .SYNOPSIS Moves a Box folder to another one. .DESCRIPTION Moves a Box folder to another one. Destination parent folder must already exist. .PARAMETER folderID Specifies the Box folder ID (mandatory). .PARAMETER parentID The ID of the destination folder. This becomes the new parent. .PARAMETER asuserID Specifies the as-user Box user ID (optional). .OUTPUTS None .EXAMPLE PS> Move-BoxFolder -folderID "11111" -parentID "22222" -asuserID "33333" #> } Function Remove-BoxCollaboration{ Param ([Parameter(Mandatory=$true)][string]$collaborationID,[string]$asuserID) if ($asuserID) { box collaborations:delete $collaborationID --as-user $asuserID } else { box collaborations:delete $collaborationID } <# .SYNOPSIS Deletes a collaboration on files or folders. .DESCRIPTION Deletes a collaboration on a file or folder using the collaboration ID. Get the collaboration using Get-BoxFolderCollaborations .PARAMETER collaborationID Specifies the collaboration ID to remove (mandatory). .PARAMETER asuserID Specifies the as-user Box user ID (optional). .OUTPUTS None .EXAMPLE PS> Remove-BoxCollaboration -collaborationID "22222" -asuser "11111" #> } Function Get-BoxFile{ Param ([Parameter(Mandatory=$true)][string]$fileID,[string]$asuserID) if ($asuserID) { $file = box files:get $fileID --as-user=$asuserID --json | ConvertFrom-Json } else { $file = box folders:get $fileID --json | ConvertFrom-Json } if ($file) { write-host "Found Box file $fileID" return $file } else { write-host "Error: The Box file $fileID was not found" -ForegroundColor Red exit } <# .SYNOPSIS Gets a Box file info from the ID using Box CLI. .DESCRIPTION Gets a Box foldfileer info from the ID using Box CLI. Requires the Box file ID and the user ID as inputs. .PARAMETER folderID Specifies the Box folder ID (mandatory). .PARAMETER asuserID Specifies the Box user ID (optional). .INPUTS Box file ID, Box As-User ID. .OUTPUTS Returns an arrary containg the Box file info. .EXAMPLE PS> Get-BoxFile -fileID "11111" -asuserID "22222" #> } |