Skip to content

Commit

Permalink
!deploy v2.30.0 with multiple fixes for #193, #210, #209, #204
Browse files Browse the repository at this point in the history
## 2.30.0

* [Issue #193](#193)
  * Added: Drive Revision functions:
    * `Get-GSDriveRevision`
    * `Remove-GSDriveRevision`
    * `Update-GSDriveRevision`
* [Issue #210](#210)
  * Fixed: `Update-GSUser` was not accepting User ID's as the User parameter
* [Issue #209](#209)
  * Added: Support for inline image downloading with `Get-GSGmailMessage` where the image is not included on the Attachments property of the parsed message object.
  * Fixed: `Get-GSGmailMessage` will now automatically set the `Format` to `Raw` if either `ParseMessage` or `SaveAttachmentsTo` is passed, as `ParseMessage` is a requirement in order to be able to access the message attachments as needed.
* [Issue #204](#204)
  * Added: `Recurse` parameter to `Get-GSDriveFileList` to allow recursively listing all files and subfolders underneath the result set. Confirmed setting the `Limit` parameter also works as expected with `Recurse` included, stopping is the original limit is reached.
  * Added: `Get-GSDriveFolderSize` function to return the calculated total size of the files in the specified folder(s).
* Miscellaneous
  * Added: `Rfc822MsgId` parameter to `Get-GSGmailMessageList` to easily build a query looking for a specific RFS 822 Message ID.
  * Added: Pipeline support for `*-GSDrivePermission` functions to enable piping Drive Files into them to manage permissions without looping manually.
  • Loading branch information
scrthq authored Jul 17, 2019
2 parents f68c38f + 59344b5 commit beb2030
Show file tree
Hide file tree
Showing 15 changed files with 585 additions and 45 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
* [PSGSuite - ChangeLog](#PSGSuite---ChangeLog)
* [2.30.0](#2300)
* [2.29.0](#2290)
* [2.28.2](#2282)
* [2.28.1](#2281)
Expand Down Expand Up @@ -91,6 +92,25 @@

# PSGSuite - ChangeLog

## 2.30.0

* [Issue #193](https://github.com/scrthq/PSGSuite/issues/193)
* Added: Drive Revision functions:
* `Get-GSDriveRevision`
* `Remove-GSDriveRevision`
* `Update-GSDriveRevision`
* [Issue #210](https://github.com/scrthq/PSGSuite/issues/210)
* Fixed: `Update-GSUser` was not accepting User ID's as the User parameter
* [Issue #209](https://github.com/scrthq/PSGSuite/issues/209)
* Added: Support for inline image downloading with `Get-GSGmailMessage` where the image is not included on the Attachments property of the parsed message object.
* Fixed: `Get-GSGmailMessage` will now automatically set the `Format` to `Raw` if either `ParseMessage` or `SaveAttachmentsTo` is passed, as `ParseMessage` is a requirement in order to be able to access the message attachments as needed.
* [Issue #204](https://github.com/scrthq/PSGSuite/issues/204)
* Added: `Recurse` parameter to `Get-GSDriveFileList` to allow recursively listing all files and subfolders underneath the result set. Confirmed setting the `Limit` parameter also works as expected with `Recurse` included, stopping is the original limit is reached.
* Added: `Get-GSDriveFolderSize` function to return the calculated total size of the files in the specified folder(s).
* Miscellaneous
* Added: `Rfc822MsgId` parameter to `Get-GSGmailMessageList` to easily build a query looking for a specific RFS 822 Message ID.
* Added: Pipeline support for `*-GSDrivePermission` functions to enable piping Drive Files into them to manage permissions without looping manually.

## 2.29.0

* [Issue #201](https://github.com/scrthq/PSGSuite/issues/201)
Expand Down
2 changes: 1 addition & 1 deletion PSGSuite/PSGSuite.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'PSGSuite.psm1'

# Version number of this module.
ModuleVersion = '2.29.0'
ModuleVersion = '2.30.0'

# ID used to uniquely identify this module
GUID = '9d751152-e83e-40bb-a6db-4c329092aaec'
Expand Down
11 changes: 6 additions & 5 deletions PSGSuite/Public/Drive/Add-GSDrivePermission.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,8 @@ function Add-GSDrivePermission {
[cmdletbinding(SupportsShouldProcess = $true,ConfirmImpact = "High",DefaultParameterSetName = "Email")]
Param
(
[parameter(Mandatory = $false,Position = 0,ValueFromPipelineByPropertyName = $true)]
[Alias('Owner','PrimaryEmail','UserKey','Mail')]
[string]
$User = $Script:PSGSuite.AdminEmail,
[parameter(Mandatory = $true)]
[parameter(Mandatory = $true,Position = 0,ValueFromPipelineByPropertyName = $true)]
[Alias('Id')]
[String]
$FileId,
[parameter(Mandatory = $true)]
Expand All @@ -93,6 +90,10 @@ function Add-GSDrivePermission {
[ValidateSet("User","Group","Domain","Anyone")]
[String]
$Type,
[parameter(Mandatory = $false,Position = 1,ValueFromPipelineByPropertyName = $true)]
[Alias('Owner','PrimaryEmail','UserKey','Mail')]
[string]
$User = $Script:PSGSuite.AdminEmail,
[parameter(Mandatory = $false,ParameterSetName = "Email")]
[String]
$EmailAddress,
Expand Down
49 changes: 43 additions & 6 deletions PSGSuite/Public/Drive/Get-GSDriveFileList.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ function Get-GSDriveFileList {
.PARAMETER ParentFolderId
ID of parent folder to search to add to the filter
.PARAMETER Recurse
If True, recurses through subfolders found underneath primary search results
.PARAMETER IncludeTeamDriveItems
Whether Team Drive items should be included in results. (Default: false)
Expand Down Expand Up @@ -68,6 +71,9 @@ function Get-GSDriveFileList {
$ParentFolderId,
[parameter(Mandatory = $false)]
[Switch]
$Recurse,
[parameter(Mandatory = $false)]
[Switch]
$IncludeTeamDriveItems,
[parameter(Mandatory = $false)]
[String[]]
Expand Down Expand Up @@ -137,7 +143,7 @@ function Get-GSDriveFileList {
if ($Fields) {
$request.Fields = "$($Fields -join ",")"
}
foreach ($key in $PSBoundParameters.Keys | Where-Object {$_ -notin @('Fields','PageSize')}) {
foreach ($key in $PSBoundParameters.Keys | Where-Object { $_ -notin @('Fields','PageSize') }) {
switch ($key) {
Filter {
$FilterFmt = ($PSBoundParameters[$key] -join " and ") -replace " -eq ","=" -replace " -like ",":" -replace " -match ",":" -replace " -contains ",":" -creplace "'True'","True" -creplace "'False'","False" -replace " -in "," in " -replace " -le ",'<=' -replace " -ge ",">=" -replace " -gt ",'>' -replace " -lt ",'<' -replace " -ne ","!=" -replace " -and "," and " -replace " -or "," or " -replace " -not "," not "
Expand All @@ -164,20 +170,51 @@ function Get-GSDriveFileList {
Write-Verbose $baseVerbose
[int]$i = 1
$overLimit = $false
$originalLimit = $Limit
do {
$result = $request.Execute()
$result.Files | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru
[int]$retrieved = ($i + $result.Files.Count) - 1
if ($Recurse -and ($Limit -eq 0 -or $retrieved -lt $Limit)) {
Write-Verbose "Starting recursive search..."
if ($Limit -gt 0) {
$Limit = $Limit - $result.Files.Count
Write-Verbose "[Prerecursion] Limit reduced to $Limit to account for $($result.Files.Count) files found in main search"
}
foreach ($subFolder in ($result.Files | Where-Object { $_.MimeType -eq 'application/vnd.google-apps.folder' } | Sort-Object Name)) {
Write-Verbose "Getting recursive file list of files under subfolder $($subFolder.Name) [$($subFolder.Id)]"
$params = @{
PageSize = $PageSize
User = $User
ParentFolderId = $subfolder.Id
IncludeTeamDriveItems = $IncludeTeamDriveItems
Recurse = $true
Fields = $Fields
Limit = $Limit
Verbose = $false
}
Get-GSDriveFileList @params -OutVariable sub
Write-Verbose "Found $($sub.Count) files in subfolder $($subfolder.Name) [$($subfolder.Id)]"
[int]$retrieved += $sub.Count
if ($originalLimit -gt 0) {
$Limit = $originalLimit - $retrieved
Write-Verbose "[Postrecursion] Limit reduced to $Limit"
if ($retrieved -ge $originalLimit) {
break
}
}
}
}
if ($result.NextPageToken) {
$request.PageToken = $result.NextPageToken
}
[int]$retrieved = ($i + $result.Files.Count) - 1
Write-Verbose "Retrieved $retrieved Files..."
if ($Limit -gt 0 -and $retrieved -eq $Limit) {
Write-Verbose "Limit reached: $Limit"
if ($originalLimit -gt 0 -and $retrieved -ge $originalLimit) {
Write-Verbose "Limit reached: $originalLimit"
$overLimit = $true
}
elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) {
$newPS = $Limit - $retrieved
elseif ($originalLimit -gt 0 -and ($retrieved + $PageSize) -gt $originalLimit) {
$newPS = $originalLimit - $retrieved
Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS)
$request.PageSize = $newPS
}
Expand Down
63 changes: 63 additions & 0 deletions PSGSuite/Public/Drive/Get-GSDriveFolderSize.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
function Get-GSDriveFolderSize {
<#
.SYNOPSIS
Gets the size of the files with the specified ParentFolderId in Drive.
.DESCRIPTION
Gets the size of the files with the specified ParentFolderId in Drive.
.PARAMETER ParentFolderId
ID of parent folder to search to add to the filter
.PARAMETER Recurse
If True, recurses through subfolders found underneath primary search results
.PARAMETER Depth
Internal use only. Used to track how deep in the subfolder structure the command is currently searching when used with -Verbose
.EXAMPLE
Get-GSDriveFolderSize -ParentFolderId $id1,$id2 -Recurse
#>

[CmdletBinding()]
Param (
[parameter(Mandatory,Position = 0,ValueFromPipelineByPropertyName)]
[Alias('Id')]
[String[]]
$ParentFolderId,
[parameter()]
[Switch]
$Recurse,
[parameter()]
[Int]
$Depth = 0
)
Begin {
$final = @{
TotalSize = 0
}
}
Process {
foreach ($id in $ParentFolderId) {
$files = Get-GSDriveFileList -ParentFolderId $id -IncludeTeamDriveItems -Fields "files(name, id, size, mimeType)" -Verbose:$false
$folderTotal = ($files.Size | Measure-Object -Sum).Sum
if ($folderTotal){
Write-Verbose ("Total file size in bytes in folder ID '$id': {0}" -f $folderTotal)
$final.TotalSize += $folderTotal
}
if ($Recurse -and ($subfolders = $files | Where-Object {$_.MimeType -eq 'application/vnd.google-apps.folder'})) {
$newDepth = $Depth + 1
Write-Verbose "[Depth: $Depth > $newDepth] Recursively searching subfolder Ids: [ $($subfolders.Id -join ", ") ]"
$subFolderTotal = Get-GSDriveFolderSize -ParentFolderId $subfolders.Id -Recurse -Depth $newDepth
if ($subFolderTotal) {
$final.TotalSize += $subFolderTotal.TotalSize
}
}
}
}
End {
$final['TotalSizeInMB'] = $final['TotalSize'] / 1MB
$final['TotalSizeInGB'] = $final['TotalSize'] / 1GB
[PSCustomObject]$final
}
}
9 changes: 5 additions & 4 deletions PSGSuite/Public/Drive/Get-GSDrivePermission.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ function Get-GSDrivePermission {
[cmdletbinding(DefaultParameterSetName = "List")]
Param
(
[parameter(Mandatory = $false,Position = 0,ValueFromPipelineByPropertyName = $true)]
[parameter(Mandatory = $true,Position = 0,ValueFromPipelineByPropertyName = $true)]
[Alias('Id')]
[String]
$FileId,
[parameter(Mandatory = $false,Position = 1,ValueFromPipelineByPropertyName = $true)]
[Alias('Owner','PrimaryEmail','UserKey','Mail')]
[string]
$User = $Script:PSGSuite.AdminEmail,
[parameter(Mandatory = $true)]
[String]
$FileId,
[parameter(Mandatory = $false,ParameterSetName = "Get")]
[String[]]
$PermissionId,
Expand Down
Loading

0 comments on commit beb2030

Please sign in to comment.