From b3e90e2a1ce4990b93e07f19ed5d988f304b8386 Mon Sep 17 00:00:00 2001 From: Nate Ferrell Date: Fri, 24 May 2019 11:22:34 -0700 Subject: [PATCH 1/4] ***NO_CI*** Saving work to move workstations --- PSGSuite/PSGSuite.psd1 | 2 +- PSGSuite/Private/Get-SafeName.ps1 | 11 ++++ PSGSuite/Public/Drive/Get-GSDriveFile.ps1 | 57 +++++++++++++++++--- PSGSuite/Public/Gmail/Get-GSGmailMessage.ps1 | 2 +- 4 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 PSGSuite/Private/Get-SafeName.ps1 diff --git a/PSGSuite/PSGSuite.psd1 b/PSGSuite/PSGSuite.psd1 index 3d702e4f..8a39a7fd 100644 --- a/PSGSuite/PSGSuite.psd1 +++ b/PSGSuite/PSGSuite.psd1 @@ -12,7 +12,7 @@ RootModule = 'PSGSuite.psm1' # Version number of this module. - ModuleVersion = '2.27.0' + ModuleVersion = '2.27.1' # ID used to uniquely identify this module GUID = '9d751152-e83e-40bb-a6db-4c329092aaec' diff --git a/PSGSuite/Private/Get-SafeName.ps1 b/PSGSuite/Private/Get-SafeName.ps1 new file mode 100644 index 00000000..222c1d8c --- /dev/null +++ b/PSGSuite/Private/Get-SafeName.ps1 @@ -0,0 +1,11 @@ +function Get-SafeName { + [CmdletBinding()] + Param ( + [parameter(Mandatory,ValueFromPipeline,Position = 0)] + [String] + $Name + ) + Process { + $Name -replace "[$(([System.IO.Path]::GetInvalidFileNameChars() + [System.IO.Path]::GetInvalidPathChars()) -join '')]","_" + } +} diff --git a/PSGSuite/Public/Drive/Get-GSDriveFile.ps1 b/PSGSuite/Public/Drive/Get-GSDriveFile.ps1 index 0ecb1a24..477a98bf 100644 --- a/PSGSuite/Public/Drive/Get-GSDriveFile.ps1 +++ b/PSGSuite/Public/Drive/Get-GSDriveFile.ps1 @@ -52,7 +52,6 @@ function Get-GSDriveFile { $User = $Script:PSGSuite.AdminEmail, [parameter(Mandatory = $false)] [Alias('SaveFileTo')] - [ValidateScript({(Get-Item $_).PSIsContainer})] [String] $OutFilePath, [parameter(Mandatory = $false,ParameterSetName = "Depth")] @@ -63,7 +62,10 @@ function Get-GSDriveFile { [parameter(Mandatory = $false,ParameterSetName = "Fields")] [ValidateSet("appProperties","capabilities","contentHints","createdTime","description","explicitlyTrashed","fileExtension","folderColorRgb","fullFileExtension","hasThumbnail","headRevisionId","iconLink","id","imageMediaMetadata","isAppAuthorized","kind","lastModifyingUser","md5Checksum","mimeType","modifiedByMe","modifiedByMeTime","modifiedTime","name","originalFilename","ownedByMe","owners","parents","permissions","properties","quotaBytesUsed","shared","sharedWithMeTime","sharingUser","size","spaces","starred","thumbnailLink","thumbnailVersion","trashed","version","videoMediaMetadata","viewedByMe","viewedByMeTime","viewersCanCopyContent","webContentLink","webViewLink","writersCanShare")] [String[]] - $Fields + $Fields, + [parameter(Mandatory = $false)] + [Switch] + $Force ) Begin { if ($Projection) { @@ -98,29 +100,70 @@ function Get-GSDriveFile { $service = New-GoogleService @serviceParams try { foreach ($file in $FileId) { + $backupPath = $null $request = $service.Files.Get($file) $request.SupportsTeamDrives = $true if ($fs) { $request.Fields = $($fs -join ",") } $res = $request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru - if ($OutFilePath -and $res.FileExtension) { - $resPath = Resolve-Path $OutFilePath - $filePath = Join-Path $resPath "$($res.Name).$($res.FileExtension)" + if ($OutFilePath) { + if (Test-Path $OutFilePath) { + $outFilePathItem = Get-Item $OutFilePath -ErrorAction SilentlyContinue + if ($outFilePathItem.PSIsContainer) { + $resPath = $outFilePathItem.FullName + $cleanedName = Get-SafeName "$($res.Name).$($res.FileExtension)" + $filePath = Join-Path $resPath $cleanedName + } + elseif ($Force) { + $endings = [System.Collections.Generic.List[string]]@('.bak') + 1..100 | ForEach-Object {$endings.Add(".bak$_")} + foreach ($end in $endings) { + $backupPath = "$($outFilePathItem.FullName)$end" + if (-not (Test-Path $backupPath)) { + break + } + else { + $backupPath = $null + } + } + Write-Warning "Renaming '$($outFilePathItem.Name)' to '$($outFilePathItem.Name).bak' in case replacement download fails." + Rename-Item $outFilePathItem.FullName -NewName $backupPath -Force + $filePath = $OutFilePath + } + else { + throw "File already exists at path '$($OutFilePath)'. Please specify -Force to overwrite any files with the same name if they exist." + } + } + else { + $filePath = $OutFilePath + } Write-Verbose "Saving file to path '$filePath'" $stream = [System.IO.File]::Create($filePath) $request.Download($stream) $stream.Close() + $res | Add-Member -MemberType NoteProperty -Name OutFilePath -Value $filePath -Force + if ($backupPath) { + Write-Verbose "File has been downloaded successfully! Removing the backup file at path: $backupPath" + Remove-Item $backupPath -Recurse -Force -Confirm:$false + } } $res } } catch { + $err = $_ + if ($backupPath) { + if (Test-Path $outFilePathItem.FullName) { + Remove-Item $outFilePathItem.FullName -Recurse -Force + } + Rename-Item $backupPath -NewName $outFilePathItem.FullName -Force + } if ($ErrorActionPreference -eq 'Stop') { - $PSCmdlet.ThrowTerminatingError($_) + $PSCmdlet.ThrowTerminatingError($err) } else { - Write-Error $_ + Write-Error $err } } } diff --git a/PSGSuite/Public/Gmail/Get-GSGmailMessage.ps1 b/PSGSuite/Public/Gmail/Get-GSGmailMessage.ps1 index dc5a2dba..f0ee23cb 100644 --- a/PSGSuite/Public/Gmail/Get-GSGmailMessage.ps1 +++ b/PSGSuite/Public/Gmail/Get-GSGmailMessage.ps1 @@ -98,7 +98,7 @@ function Get-GSGmailMessage { $resPath = Resolve-Path $SaveAttachmentsTo $attachments = $parsed.Attachments foreach ($att in $attachments) { - $cleanedName = $att.FileName -replace "[$(([System.IO.Path]::GetInvalidFileNameChars() + [System.IO.Path]::GetInvalidPathChars()) -join '')]","_" + $cleanedName = Get-SafeName $att.FileName $fileName = Join-Path $resPath $cleanedName Write-Verbose "Saving attachment to path '$fileName'" $stream = [System.IO.File]::Create($fileName) From 9905851259df68a92f26eedf9a77faf316a87613 Mon Sep 17 00:00:00 2001 From: Nate Ferrell Date: Thu, 30 May 2019 00:00:28 -0500 Subject: [PATCH 2/4] ***NO_CI*** saving current progress --- .../Configuration/Export-PSGSuiteConfig.ps1 | 4 +- .../Configuration/Get-PSGSuiteConfig.ps1 | 150 +++++++++--------- 2 files changed, 79 insertions(+), 75 deletions(-) diff --git a/PSGSuite/Public/Configuration/Export-PSGSuiteConfig.ps1 b/PSGSuite/Public/Configuration/Export-PSGSuiteConfig.ps1 index a1fe48ef..9d7172a9 100644 --- a/PSGSuite/Public/Configuration/Export-PSGSuiteConfig.ps1 +++ b/PSGSuite/Public/Configuration/Export-PSGSuiteConfig.ps1 @@ -40,10 +40,8 @@ function Export-PSGSuiteConfig { } Process { try { - Write-Verbose "Updating current saved config for '$ConfigName' with P12Key and ClientSecrets contents if missing." - $baseConf | Set-PSGSuiteConfig -NoImport -Verbose:$false Write-Verbose "Exporting config '$ConfigName' to path: $Path" - Get-PSGSuiteConfig -ConfigName $ConfigName -NoImport -PassThru -Verbose:$false | Select-Object ConfigName,P12Key,ClientSecrets,AppEmail,AdminEmail,CustomerId,Domain,Preference | ConvertTo-Json -Depth 5 -Compress -Verbose:$false | Set-Content -Path $Path -Verbose:$false + $baseConf | Select-Object ConfigName,P12Key,ClientSecrets,AppEmail,AdminEmail,CustomerId,Domain,Preference | ConvertTo-Json -Depth 5 -Compress -Verbose:$false | Set-Content -Path $Path -Verbose:$false } catch { $PSCmdlet.ThrowTerminatingError($_) diff --git a/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 b/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 index e71116af..24ebd386 100644 --- a/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 +++ b/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 @@ -46,85 +46,91 @@ function Get-PSGSuiteConfig { [Switch] $NoImport ) - function Decrypt { - param($String) - if ($String -is [System.Security.SecureString]) { - [System.Runtime.InteropServices.Marshal]::PtrToStringAuto( - [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR( - $string)) - } - elseif ($String -is [System.String]) { - $String - } - } - $script:ConfigScope = $Scope - switch ($PSCmdlet.ParameterSetName) { - ConfigurationModule { - $fullConf = Import-SpecificConfiguration -CompanyName 'SCRT HQ' -Name 'PSGSuite' -Scope $Script:ConfigScope - if (!$ConfigName) { - $choice = $fullConf["DefaultConfig"] - Write-Verbose "Importing default config: $choice" + Begin { + function Decrypt { + param($String) + if ($String -is [System.Security.SecureString]) { + [System.Runtime.InteropServices.Marshal]::PtrToStringAuto( + [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR( + $String)) } else { - $choice = $ConfigName - Write-Verbose "Importing config: $choice" + $String } - $encConf = [PSCustomObject]($fullConf[$choice]) } - Path { - $encConf = switch ((Get-Item -Path $Path).Extension) { - '.xml' { - Import-Clixml -Path $Path - $choice = "LegacyXML" + $outputProps = @( + @{l = 'ConfigName';e = {$choice}}, + @{l = 'P12KeyPath';e = {Decrypt $_.P12KeyPath}}, + 'P12Key', + @{l = 'ClientSecretsPath';e = {Decrypt $_.ClientSecretsPath}}, + @{l = 'ClientSecrets';e = {Decrypt $_.ClientSecrets}}, + @{l = 'AppEmail';e = {Decrypt $_.AppEmail}}, + @{l = 'AdminEmail';e = {Decrypt $_.AdminEmail}}, + @{l = 'CustomerID';e = {Decrypt $_.CustomerID}}, + @{l = 'Domain';e = {Decrypt $_.Domain}}, + @{l = 'Preference';e = {Decrypt $_.Preference}}, + @{l = 'ServiceAccountClientID';e = {Decrypt $_.ServiceAccountClientID}}, + @{l = 'Chat';e = { + $dict = @{ + Webhooks = @{} + Spaces = @{} + } + foreach ($key in $_.Chat.Webhooks.Keys) { + $dict['Webhooks'][$key] = (Decrypt $_.Chat.Webhooks[$key]) + } + foreach ($key in $_.Chat.Spaces.Keys) { + $dict['Spaces'][$key] = (Decrypt $_.Chat.Spaces[$key]) + } + $dict + }}, + @{l = 'ConfigPath';e = { + if ($_.ConfigPath) { + $_.ConfigPath + } + elseif ($Path) { + (Resolve-Path $Path).Path + } + else { + $null } - '.psd1' { - Import-SpecificConfiguration -Path $Path - $choice = "CustomConfigurationFile" + }} + ) + } + Process { + $script:ConfigScope = $Scope + switch ($PSCmdlet.ParameterSetName) { + ConfigurationModule { + $fullConf = Import-SpecificConfiguration -CompanyName 'SCRT HQ' -Name 'PSGSuite' -Scope $Script:ConfigScope + if (!$ConfigName) { + $choice = $fullConf["DefaultConfig"] + Write-Verbose "Importing default config: $choice" + } + else { + $choice = $ConfigName + Write-Verbose "Importing config: $choice" + } + $encConf = [PSCustomObject]($fullConf[$choice]) + } + Path { + $encConf = switch ((Get-Item -Path $Path).Extension) { + '.xml' { + Import-Clixml -Path $Path + $choice = "LegacyXML" + } + '.psd1' { + Import-SpecificConfiguration -Path $Path + $choice = "CustomConfigurationFile" + } } } } - } - $decryptedConfig = $encConf | - Select-Object -Property @{l = 'ConfigName';e = {$choice}}, - @{l = 'P12KeyPath';e = {Decrypt $_.P12KeyPath}}, - P12Key, - @{l = 'ClientSecretsPath';e = {Decrypt $_.ClientSecretsPath}}, - @{l = 'ClientSecrets';e = {Decrypt $_.ClientSecrets}}, - @{l = 'AppEmail';e = {Decrypt $_.AppEmail}}, - @{l = 'AdminEmail';e = {Decrypt $_.AdminEmail}}, - @{l = 'CustomerID';e = {Decrypt $_.CustomerID}}, - @{l = 'Domain';e = {Decrypt $_.Domain}}, - @{l = 'Preference';e = {Decrypt $_.Preference}}, - @{l = 'ServiceAccountClientID';e = {Decrypt $_.ServiceAccountClientID}}, - @{l = 'Chat';e = { - $dict = @{ - Webhooks = @{} - Spaces = @{} - } - foreach ($key in $_.Chat.Webhooks.Keys) { - $dict['Webhooks'][$key] = (Decrypt $_.Chat.Webhooks[$key]) - } - foreach ($key in $_.Chat.Spaces.Keys) { - $dict['Spaces'][$key] = (Decrypt $_.Chat.Spaces[$key]) - } - $dict - }}, - @{l = 'ConfigPath';e = {if ($_.ConfigPath) { - $_.ConfigPath - } - elseif ($Path) { - "$(Resolve-Path $Path)" - } - else { - $null - } - } - } - Write-Verbose "Retrieved configuration '$choice'" - if (!$NoImport) { - $script:PSGSuite = $decryptedConfig - } - if ($PassThru) { - $decryptedConfig + $decryptedConfig = $encConf | Select-Object -Property $outputProps + Write-Verbose "Retrieved configuration '$choice'" + if (!$NoImport) { + $script:PSGSuite = $decryptedConfig + } + if ($PassThru) { + $decryptedConfig + } } } From a6b1ed77980f4f041bcfc6b3c67ac4ccebf54569 Mon Sep 17 00:00:00 2001 From: Nate Ferrell Date: Thu, 30 May 2019 13:11:48 -0500 Subject: [PATCH 3/4] pushing current local progress to origin --- CHANGELOG.md | 21 +++ PSGSuite/Aliases/PSGSuite.Aliases.ps1 | 11 +- PSGSuite/PSGSuite.psd1 | 2 +- ...{Get-SafeName.ps1 => Get-SafeFileName.ps1} | 2 +- PSGSuite/Public/Drive/Get-GSDrive.ps1 | 135 ++++++++++++++++++ PSGSuite/Public/Drive/Get-GSDriveFile.ps1 | 2 +- PSGSuite/Public/Drive/Get-GSTeamDrive.ps1 | 91 ------------ PSGSuite/Public/Gmail/Get-GSGmailMessage.ps1 | 2 +- .../Public/Groups/Test-GSGroupMembership.ps1 | 28 ++-- .../Public/Reports/Get-GSActivityReport.ps1 | 28 +++- PSGSuite/Public/Reports/Get-GSUsageReport.ps1 | 30 +++- build.ps1 | 73 ---------- psake.ps1 | 39 +++-- 13 files changed, 257 insertions(+), 207 deletions(-) rename PSGSuite/Private/{Get-SafeName.ps1 => Get-SafeFileName.ps1} (91%) create mode 100644 PSGSuite/Public/Drive/Get-GSDrive.ps1 delete mode 100644 PSGSuite/Public/Drive/Get-GSTeamDrive.ps1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ff0024d..26967894 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog * [Changelog](#changelog) + * [2.28.0 - 2019-05-31](#2280---2019-05-31) * [2.27.0](#2270) * [2.26.4](#2264) * [2.26.3](#2263) @@ -87,6 +88,26 @@ *** +## 2.28.0 - 2019-05-31 + +* [Issue #188](https://github.com/scrthq/PSGSuite/issues/188) + * Added: `Get-GSDriveFile` now supports specifying a full file path. + * Fixed: `Get-GSDriveFile` will now replace any special path characters in the filename with underscores + * Added: The File object returned by `Get-GSDriveFile` will now include an additional `OutFilePath` property if the file is downloaded. This property will contain the full path to the downloaded file. +* [Issue #190](https://github.com/scrthq/PSGSuite/issues/190) + * Fixed: `Fields` parameter on `Get-GSDriveFile` was not being honored. +* [Issue #195](https://github.com/scrthq/PSGSuite/issues/195) + * Added: `Limit` parameter with `First` alias to the following List functions: + * `Get-GSActivityReport` + * `Get-GSDrive` + * `Get-GSTeamDrive` +* [Issue #196](https://github.com/scrthq/PSGSuite/issues/196) + * Fixed: `Get-GSTeamDrive` was not paginating through the results. +* Miscellaneous + * Fixed: `Export-PSGSuiteConfig` is faster due to safely assuming that the P12Key and/or ClientSecrets values have already been pulled from the corresponding keys. + * Fixed: Incomplete documentation for `Test-GSGroupMembership`. + * Added: `UseDomainAdminAccess` switch parameter to `Get-GSTeamDrive` + ## 2.27.0 * [Issue #185](https://github.com/scrthq/PSGSuite/issues/185) diff --git a/PSGSuite/Aliases/PSGSuite.Aliases.ps1 b/PSGSuite/Aliases/PSGSuite.Aliases.ps1 index 96521b5c..4942df43 100644 --- a/PSGSuite/Aliases/PSGSuite.Aliases.ps1 +++ b/PSGSuite/Aliases/PSGSuite.Aliases.ps1 @@ -1,8 +1,8 @@ @{ 'Add-GSDriveFilePermissions' = 'Add-GSDrivePermission' 'Export-PSGSuiteConfiguration' = 'Set-PSGSuiteConfig' - 'Get-GSCalendarResourceList' = 'Get-GSResourceList' 'Get-GSCalendarEventList' = 'Get-GSCalendarEvent' + 'Get-GSCalendarResourceList' = 'Get-GSResourceList' 'Get-GSDataTransferApplicationList' = 'Get-GSDataTransferApplication' 'Get-GSDriveFileInfo' = 'Get-GSDriveFile' 'Get-GSDriveFilePermissionsList' = 'Get-GSDrivePermission' @@ -10,6 +10,8 @@ 'Get-GSGmailFilterList' = 'Get-GSGmailFilter' 'Get-GSGmailLabelList' = 'Get-GSGmailLabel' 'Get-GSGmailMessageInfo' = 'Get-GSGmailMessage' + 'Get-GSGmailSendAsSettings' = 'Get-GSGmailSendAsAlias' + 'Get-GSGmailSignature' = 'Get-GSGmailSendAsAlias' 'Get-GSGroupList' = 'Get-GSGroup' 'Get-GSGroupMemberList' = 'Get-GSGroupMember' 'Get-GSMobileDeviceList' = 'Get-GSMobileDevice' @@ -19,7 +21,8 @@ 'Get-GSOU' = 'Get-GSOrganizationalUnit' 'Get-GSResourceList' = 'Get-GSResource' 'Get-GSShortURLInfo' = 'Get-GSShortURL' - 'Get-GSTeamDrivesList' = 'Get-GSTeamDrive' + 'Get-GSTeamDrive' = 'Get-GSDrive' + 'Get-GSTeamDrivesList' = 'Get-GSDrive' 'Get-GSUserASPList' = 'Get-GSUserASP' 'Get-GSUserLicenseInfo' = 'Get-GSUserLicense' 'Get-GSUserLicenseList' = 'Get-GSUserLicense' @@ -34,8 +37,6 @@ 'Set-PSGSuiteDefaultDomain' = 'Switch-PSGSuiteConfig' 'Switch-PSGSuiteDomain' = 'Switch-PSGSuiteConfig' 'Update-GSCalendarResource' = 'Update-GSResource' - 'Update-GSSheetValue' = 'Export-GSSheet' - 'Get-GSGmailSignature' = 'Get-GSGmailSendAsAlias' - 'Get-GSGmailSendAsSettings' = 'Get-GSGmailSendAsAlias' 'Update-GSGmailSendAsSettings' = 'Update-GSGmailSendAsAlias' + 'Update-GSSheetValue' = 'Export-GSSheet' } diff --git a/PSGSuite/PSGSuite.psd1 b/PSGSuite/PSGSuite.psd1 index 8a39a7fd..bc4ed595 100644 --- a/PSGSuite/PSGSuite.psd1 +++ b/PSGSuite/PSGSuite.psd1 @@ -12,7 +12,7 @@ RootModule = 'PSGSuite.psm1' # Version number of this module. - ModuleVersion = '2.27.1' + ModuleVersion = '2.28.0' # ID used to uniquely identify this module GUID = '9d751152-e83e-40bb-a6db-4c329092aaec' diff --git a/PSGSuite/Private/Get-SafeName.ps1 b/PSGSuite/Private/Get-SafeFileName.ps1 similarity index 91% rename from PSGSuite/Private/Get-SafeName.ps1 rename to PSGSuite/Private/Get-SafeFileName.ps1 index 222c1d8c..c5fb6fe2 100644 --- a/PSGSuite/Private/Get-SafeName.ps1 +++ b/PSGSuite/Private/Get-SafeFileName.ps1 @@ -1,4 +1,4 @@ -function Get-SafeName { +function Get-SafeFileName { [CmdletBinding()] Param ( [parameter(Mandatory,ValueFromPipeline,Position = 0)] diff --git a/PSGSuite/Public/Drive/Get-GSDrive.ps1 b/PSGSuite/Public/Drive/Get-GSDrive.ps1 new file mode 100644 index 00000000..f9db7c3e --- /dev/null +++ b/PSGSuite/Public/Drive/Get-GSDrive.ps1 @@ -0,0 +1,135 @@ +function Get-GSDrive { + <# + .SYNOPSIS + Gets information about a Shared Drive + + .DESCRIPTION + Gets information about a Shared Drive + + .PARAMETER DriveId + The unique Id of the Shared Drive. If excluded, the list of Shared Drives will be returned + + .PARAMETER User + The email or unique Id of the user with access to the Shared Drive + + .PARAMETER Filter + Query string for searching Shared Drives. See the "Search for Files and Shared Drives" guide for the supported syntax: https://developers.google.com/drive/v3/web/search-parameters + + PowerShell filter syntax here is supported as "best effort". Please use Google's filter operators and syntax to ensure best results + + .PARAMETER UseDomainAdminAccess + Issue the request as a domain administrator; if set to true, then all Shared Drives of the domain in which the requester is an administrator are returned. + + .PARAMETER PageSize + The page size of the result set + + .PARAMETER Limit + The maximum amount of results you want returned. Exclude or set to 0 to return all results + + .EXAMPLE + Get-GSDrive -Limit 3 -UseDomainAdminAccess + + Gets the first 3 Shared Drives in the domain. + #> + [OutputType('Google.Apis.Drive.v3.Data.Drive')] + [cmdletbinding(DefaultParameterSetName = "List")] + Param + ( + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true,ParameterSetName = "Get")] + [Alias('Id','TeamDriveId')] + [String[]] + $DriveId, + [parameter(Mandatory = $false,Position = 0,ValueFromPipelineByPropertyName = $true)] + [Alias('Owner','PrimaryEmail','UserKey','Mail')] + [string] + $User = $Script:PSGSuite.AdminEmail, + [parameter(Mandatory = $false,ParameterSetName = "List")] + [Alias('Q','Query')] + [String] + $Filter, + [parameter(Mandatory = $false,ParameterSetName = "List")] + [Switch] + $UseDomainAdminAccess, + [parameter(Mandatory = $false,ParameterSetName = "List")] + [ValidateRange(1,100)] + [Int] + $PageSize = "100", + [parameter(Mandatory = $false,ParameterSetName = "List")] + [Alias('First')] + [Int] + $Limit = 0 + ) + Process { + if ($UseDomainAdminAccess -or $User -ceq 'me') { + $User = $Script:PSGSuite.AdminEmail + } + elseif ($User -notlike "*@*.*") { + $User = "$($User)@$($Script:PSGSuite.Domain)" + } + $serviceParams = @{ + Scope = 'https://www.googleapis.com/auth/drive' + ServiceType = 'Google.Apis.Drive.v3.DriveService' + User = $User + } + $service = New-GoogleService @serviceParams + try { + switch ($PSCmdlet.ParameterSetName) { + Get { + foreach ($id in $DriveId) { + $request = $service.Drives.Get($id) + Write-Verbose "Getting Shared Drive '$id' for user '$User'" + $request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru + } + } + List { + $request = $service.Drives.List() + if ($Limit -gt 0 -and $PageSize -gt $Limit) { + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with first page" -f $PageSize,$Limit) + $PageSize = $Limit + } + $request.PageSize = $PageSize + if ($UseDomainAdminAccess) { + $request.UseDomainAdminAccess = $true + Write-Verbose "Getting Shared Drives as Domain Admin" + } + else { + Write-Verbose "Getting Shared Drives for user '$User'" + } + if ($Filter) { + $FilterFmt = $Filter -replace " -eq ","=" -replace " -like "," contains " -replace " -match "," contains " -replace " -contains "," 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 " + $request.Q = $($FilterFmt -join " ") + } + [int]$i = 1 + $overLimit = $false + do { + $result = $request.Execute() + if ($result.Drives) { + $result.Drives | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru + } + $request.PageToken = $result.NextPageToken + [int]$retrieved = ($i + $result.Drives.Count) - 1 + Write-Verbose "Retrieved $retrieved Shared Drives..." + if ($Limit -gt 0 -and $retrieved -eq $Limit) { + $overLimit = $true + } + elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { + $newPS = $Limit - $retrieved + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) + $request.PageSize = $newPS + } + [int]$i = $i + $result.Drives.Count + } + until ($overLimit -or !$result.NextPageToken) + } + } + } + catch { + if ($ErrorActionPreference -eq 'Stop') { + $PSCmdlet.ThrowTerminatingError($_) + } + else { + Write-Error $_ + } + } + } +} diff --git a/PSGSuite/Public/Drive/Get-GSDriveFile.ps1 b/PSGSuite/Public/Drive/Get-GSDriveFile.ps1 index 477a98bf..d751b5c8 100644 --- a/PSGSuite/Public/Drive/Get-GSDriveFile.ps1 +++ b/PSGSuite/Public/Drive/Get-GSDriveFile.ps1 @@ -112,7 +112,7 @@ function Get-GSDriveFile { $outFilePathItem = Get-Item $OutFilePath -ErrorAction SilentlyContinue if ($outFilePathItem.PSIsContainer) { $resPath = $outFilePathItem.FullName - $cleanedName = Get-SafeName "$($res.Name).$($res.FileExtension)" + $cleanedName = Get-SafeFileName "$($res.Name).$($res.FileExtension)" $filePath = Join-Path $resPath $cleanedName } elseif ($Force) { diff --git a/PSGSuite/Public/Drive/Get-GSTeamDrive.ps1 b/PSGSuite/Public/Drive/Get-GSTeamDrive.ps1 deleted file mode 100644 index 56cd11cd..00000000 --- a/PSGSuite/Public/Drive/Get-GSTeamDrive.ps1 +++ /dev/null @@ -1,91 +0,0 @@ -function Get-GSTeamDrive { - <# - .SYNOPSIS - Gets information about a Team Drive - - .DESCRIPTION - Gets information about a Team Drive - - .PARAMETER TeamDriveId - The unique Id of the Team Drive. If excluded, the list of Team Drives will be returned - - .PARAMETER User - The email or unique Id of the user with access to the Team Drive - - .PARAMETER Filter - Query string for searching Team Drives. See the "Search for Files and Team Drives" guide for the supported syntax: https://developers.google.com/drive/v3/web/search-parameters - - PowerShell filter syntax here is supported as "best effort". Please use Google's filter operators and syntax to ensure best results - - .PARAMETER PageSize - The page size of the result set - - .EXAMPLE - - #> - [OutputType('Google.Apis.Drive.v3.Data.TeamDrive')] - [cmdletbinding(DefaultParameterSetName = "List")] - Param - ( - [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true,ParameterSetName = "Get")] - [Alias('Id')] - [String[]] - $TeamDriveId, - [parameter(Mandatory = $false,Position = 0,ValueFromPipelineByPropertyName = $true)] - [Alias('Owner','PrimaryEmail','UserKey','Mail')] - [string] - $User = $Script:PSGSuite.AdminEmail, - [parameter(Mandatory = $false,ParameterSetName = "List")] - [Alias('Q','Query')] - [String] - $Filter, - [parameter(Mandatory = $false,ParameterSetName = "List")] - [ValidateRange(1,100)] - [Int] - $PageSize = "100" - ) - Process { - if ($User -ceq 'me') { - $User = $Script:PSGSuite.AdminEmail - } - elseif ($User -notlike "*@*.*") { - $User = "$($User)@$($Script:PSGSuite.Domain)" - } - $serviceParams = @{ - Scope = 'https://www.googleapis.com/auth/drive' - ServiceType = 'Google.Apis.Drive.v3.DriveService' - User = $User - } - $service = New-GoogleService @serviceParams - try { - switch ($PSCmdlet.ParameterSetName) { - Get { - foreach ($id in $TeamDriveId) { - $request = $service.Teamdrives.Get($id) - Write-Verbose "Getting Team Drive '$id' for user '$User'" - $request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru - } - } - List { - $request = $service.Teamdrives.List() - $request.PageSize = $PageSize - if ($Filter) { - $FilterFmt = $Filter -replace " -eq ","=" -replace " -like "," contains " -replace " -match "," contains " -replace " -contains "," 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 " - $request.UseDomainAdminAccess = $true - $request.Q = $($FilterFmt -join " ") - } - Write-Verbose "Getting Team Drives for user '$User'" - $request.Execute() | Select-Object -ExpandProperty TeamDrives | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru - } - } - } - catch { - if ($ErrorActionPreference -eq 'Stop') { - $PSCmdlet.ThrowTerminatingError($_) - } - else { - Write-Error $_ - } - } - } -} diff --git a/PSGSuite/Public/Gmail/Get-GSGmailMessage.ps1 b/PSGSuite/Public/Gmail/Get-GSGmailMessage.ps1 index f0ee23cb..73289a9a 100644 --- a/PSGSuite/Public/Gmail/Get-GSGmailMessage.ps1 +++ b/PSGSuite/Public/Gmail/Get-GSGmailMessage.ps1 @@ -98,7 +98,7 @@ function Get-GSGmailMessage { $resPath = Resolve-Path $SaveAttachmentsTo $attachments = $parsed.Attachments foreach ($att in $attachments) { - $cleanedName = Get-SafeName $att.FileName + $cleanedName = Get-SafeFileName $att.FileName $fileName = Join-Path $resPath $cleanedName Write-Verbose "Saving attachment to path '$fileName'" $stream = [System.IO.File]::Create($fileName) diff --git a/PSGSuite/Public/Groups/Test-GSGroupMembership.ps1 b/PSGSuite/Public/Groups/Test-GSGroupMembership.ps1 index 8e3fc951..b603d20e 100644 --- a/PSGSuite/Public/Groups/Test-GSGroupMembership.ps1 +++ b/PSGSuite/Public/Groups/Test-GSGroupMembership.ps1 @@ -17,7 +17,7 @@ function Test-GSGroupMembership { .EXAMPLE Test-GSGroupMembership -Identity admins@domain.com -Member john@domain.com - Gets the group settings for admins@domain.com + Tests if john@domain.com is a member of admins@domain.com #> [OutputType('Google.Apis.Admin.Directory.directory_v1.Data.MembersHasMember')] [cmdletbinding()] @@ -30,7 +30,7 @@ function Test-GSGroupMembership { [parameter(Mandatory = $true,ValueFromPipelineByPropertyName = $true,Position = 1)] [Alias("PrimaryEmail","UserKey","Mail","User","UserEmail","Members")] [ValidateNotNullOrEmpty()] - [String] + [String[]] $Member ) Begin { @@ -41,18 +41,20 @@ function Test-GSGroupMembership { $service = New-GoogleService @serviceParams } Process { - try { - Resolve-Email ([ref]$Identity),([ref]$Member) - Write-Verbose "Checking if group '$Identity' has member '$Member'" - $request = $service.Members.HasMember($Identity,$Member) - $request.Execute() | Add-Member -MemberType NoteProperty -Name 'Group' -Value $Identity -Force -PassThru | Add-Member -MemberType NoteProperty -Name 'Member' -Value $Member -Force -PassThru - } - catch { - if ($ErrorActionPreference -eq 'Stop') { - $PSCmdlet.ThrowTerminatingError($_) + foreach ($mem in $Member) { + try { + Resolve-Email ([ref]$Identity),([ref]$mem) + Write-Verbose "Checking if group '$Identity' has member '$mem'" + $request = $service.Members.HasMember($Identity,$mem) + $request.Execute() | Add-Member -MemberType NoteProperty -Name 'Group' -Value $Identity -Force -PassThru | Add-Member -MemberType NoteProperty -Name 'Member' -Value $mem -Force -PassThru } - else { - Write-Error $_ + catch { + if ($ErrorActionPreference -eq 'Stop') { + $PSCmdlet.ThrowTerminatingError($_) + } + else { + Write-Error $_ + } } } } diff --git a/PSGSuite/Public/Reports/Get-GSActivityReport.ps1 b/PSGSuite/Public/Reports/Get-GSActivityReport.ps1 index fdadf1d8..9fd0dfea 100644 --- a/PSGSuite/Public/Reports/Get-GSActivityReport.ps1 +++ b/PSGSuite/Public/Reports/Get-GSActivityReport.ps1 @@ -40,6 +40,9 @@ function Get-GSActivityReport { .PARAMETER PageSize Number of activity records to be shown in each page + .PARAMETER Limit + The maximum amount of results you want returned. Exclude or set to 0 to return all results + .EXAMPLE Get-GSActivityReport -StartTime (Get-Date).AddDays(-30) @@ -76,7 +79,11 @@ function Get-GSActivityReport { [ValidateRange(1,1000)] [Alias("MaxResults")] [Int] - $PageSize = "1000" + $PageSize = "1000", + [parameter(Mandatory = $false)] + [Alias('First')] + [Int] + $Limit = 0 ) Begin { $serviceParams = @{ @@ -92,6 +99,10 @@ function Get-GSActivityReport { } Write-Verbose "Getting $ApplicationName Activity report" $request = $service.Activities.List($UserKey,($ApplicationName.ToLower())) + if ($Limit -gt 0 -and $PageSize -gt $Limit) { + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with first page" -f $PageSize,$Limit) + $PageSize = $Limit + } $request.MaxResults = $PageSize foreach ($key in $PSBoundParameters.Keys | Where-Object {$_ -notin @('UserKey','ApplicationName')}) { switch ($key) { @@ -111,18 +122,25 @@ function Get-GSActivityReport { } } } - $response = @() [int]$i = 1 + $overLimit = $false do { $result = $request.Execute() - $response += $result.Items + $result.Items $request.PageToken = $result.NextPageToken [int]$retrieved = ($i + $result.Items.Count) - 1 Write-Verbose "Retrieved $retrieved events..." + if ($Limit -gt 0 -and $retrieved -eq $Limit) { + $overLimit = $true + } + elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { + $newPS = $Limit - $retrieved + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) + $request.MaxResults = $newPS + } [int]$i = $i + $result.Items.Count } - until (!$result.NextPageToken) - return $response + until ($overLimit -or !$result.NextPageToken) } catch { if ($ErrorActionPreference -eq 'Stop') { diff --git a/PSGSuite/Public/Reports/Get-GSUsageReport.ps1 b/PSGSuite/Public/Reports/Get-GSUsageReport.ps1 index bf6b1752..aeae5857 100644 --- a/PSGSuite/Public/Reports/Get-GSUsageReport.ps1 +++ b/PSGSuite/Public/Reports/Get-GSUsageReport.ps1 @@ -36,14 +36,16 @@ function Get-GSUsageReport { .PARAMETER PageSize Maximum number of results to return. Maximum allowed is 1000 + .PARAMETER Limit + The maximum amount of results you want returned. Exclude or set to 0 to return all results + .EXAMPLE Get-GSUsageReport -Date (Get-Date).AddDays(-30) Gets the Customer Usage report from 30 days prior #> [cmdletbinding(DefaultParameterSetName = "Customer")] - Param - ( + Param ( [parameter(Mandatory = $false,ParameterSetName = "Customer")] [parameter(Mandatory = $false,ParameterSetName = "Entity")] [parameter(Mandatory = $false,ParameterSetName = "User")] @@ -74,6 +76,11 @@ function Get-GSUsageReport { [Alias("MaxResults")] [Int] $PageSize = "1000", + [parameter(Mandatory = $false,ParameterSetName = "Entity")] + [parameter(Mandatory = $false,ParameterSetName = "User")] + [Alias('First')] + [Int] + $Limit = 0, [parameter(Mandatory = $false)] [switch] $Flat, @@ -97,6 +104,10 @@ function Get-GSUsageReport { } Entity { $request = $service.EntityUsageReports.Get($EntityType,$EntityKey,($Date.ToString('yyyy-MM-dd'))) + if ($Limit -gt 0 -and $PageSize -gt $Limit) { + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with first page" -f $PageSize,$Limit) + $PageSize = $Limit + } $request.MaxResults = $PageSize } User { @@ -107,6 +118,10 @@ function Get-GSUsageReport { $UserKey = "$($UserKey)@$($Script:PSGSuite.Domain)" } $request = $service.UserUsageReport.Get($UserKey,($Date.ToString('yyyy-MM-dd'))) + if ($Limit -gt 0 -and $PageSize -gt $Limit) { + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with first page" -f $PageSize,$Limit) + $PageSize = $Limit + } $request.MaxResults = $PageSize } } @@ -127,6 +142,7 @@ function Get-GSUsageReport { } $warnings = @() [int]$i = 1 + $overLimit = $false do { $result = $request.Execute() if ($Raw) { @@ -186,9 +202,17 @@ function Get-GSUsageReport { $request.PageToken = $result.NextPageToken [int]$retrieved = ($i + $result.UsageReportsValue.Count) - 1 Write-Verbose "Retrieved $retrieved entities for this report..." + if ($Limit -gt 0 -and $retrieved -eq $Limit) { + $overLimit = $true + } + elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { + $newPS = $Limit - $retrieved + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) + $request.MaxResults = $newPS + } [int]$i = $i + $result.UsageReportsValue.Count } - until (!$result.NextPageToken) + until ($overLimit -or !$result.NextPageToken) if ($warnings | Where-Object {$_.Code}) { $warnings | ForEach-Object { Write-Warning "[$($_.Code)] $($_.Message)" diff --git a/build.ps1 b/build.ps1 index b6cc6c78..b7c345e8 100644 --- a/build.ps1 +++ b/build.ps1 @@ -51,79 +51,6 @@ Invoke-CommandWithLog {$PSDefaultParameterValues = @{ 'Install-Module:Verbose' = $false }} -<# -# build/init script borrowed from PoshBot x Brandon Olin - -function Resolve-Module { - [Cmdletbinding()] - param ( - [Parameter(Mandatory, ValueFromPipeline)] - [string[]]$Name, - - [switch]$UpdateModules - ) - - begin { - Get-PackageProvider -Name Nuget -ForceBootstrap -Verbose:$false | Out-Null - Set-PSRepository -Name PSGallery -InstallationPolicy Trusted -Verbose:$false - - $PSDefaultParameterValues = @{ - '*-Module:Verbose' = $false - 'Find-Module:Repository' = 'PSGallery' - 'Import-Module:ErrorAction' = 'Stop' - 'Import-Module:Verbose' = $false - 'Import-Module:Force' = $true - 'Install-Module:ErrorAction' = 'Stop' - 'Install-Module:Force' = $true - 'Install-Module:Scope' = 'CurrentUser' - 'Install-Module:Verbose' = $false - 'Install-Module:AllowClobber' = $true - 'Install-Module:Repository' = 'PSGallery' - } - } - - process { - foreach ($moduleName in $Name) { - $versionToImport = '' - - Write-Verbose -Message "Resolving Module [$($moduleName)]" - if ($Module = Get-Module -Name $moduleName -ListAvailable -Verbose:$false) { - # Determine latest version on PSGallery and warn us if we're out of date - $latestLocalVersion = ($Module | Measure-Object -Property Version -Maximum).Maximum - $latestGalleryVersion = (Find-Module -Name $moduleName -Repository PSGallery | - Measure-Object -Property Version -Maximum).Maximum - - # Out we out of date? - if ($latestLocalVersion -lt $latestGalleryVersion) { - if ($UpdateModules) { - Write-Verbose -Message "$($moduleName) installed version [$($latestLocalVersion.ToString())] is outdated. Installing gallery version [$($latestGalleryVersion.ToString())]" - if ($UpdateModules) { - Install-Module -Name $moduleName -RequiredVersion $latestGalleryVersion - $versionToImport = $latestGalleryVersion - } - } else { - Write-Warning "$($moduleName) is out of date. Latest version on PSGallery is [$latestGalleryVersion]. To update, use the -UpdateModules switch." - } - } else { - $versionToImport = $latestLocalVersion - } - } else { - Write-Verbose -Message "[$($moduleName)] missing. Installing..." - Install-Module -Name $moduleName -Repository PSGallery - $versionToImport = (Get-Module -Name $moduleName -ListAvailable | Measure-Object -Property Version -Maximum).Maximum - } - - Write-Verbose -Message "$($moduleName) installed. Importing..." - if (-not [string]::IsNullOrEmpty($versionToImport)) { - Import-module -Name $moduleName -RequiredVersion $versionToImport - } else { - Import-module -Name $moduleName - } - } - } -} -#> - $update = @{} $verbose = @{} if ($PSBoundParameters.ContainsKey('UpdateModules')) { diff --git a/psake.ps1 b/psake.ps1 index f18b9501..5f27dd42 100644 --- a/psake.ps1 +++ b/psake.ps1 @@ -65,16 +65,22 @@ task Clean -depends Init { Remove-Module -Name $env:BHProjectName -Force -ErrorAction SilentlyContinue if (Test-Path -Path $outputDir) { - Get-ChildItem -Path $outputDir -Recurse | Sort-Object {$_.FullName.Length} -Descending | ForEach-Object { - try { - Remove-Item $_.FullName -Force -Recurse - } - catch { - Write-Warning "Unable to delete: '$($_.FullName)'" + if ("$env:NoNugetRestore" -eq 'True') { + Write-BuildLog "Skipping DLL clean due to `$env:NoNugetRestore = $env:NoNugetRestore" + Get-ChildItem -Path $outputDir -Recurse -File | Where-Object {$_.FullName -notlike "$outputModVerDir\lib*"} | Sort-Object {$_.FullName.Length} -Descending | ForEach-Object { + try { + Remove-Item $_.FullName -Force -Recurse + } + catch { + Write-Warning "Unable to delete: '$($_.FullName)'" + } } } + else { + Remove-Item $outputDir -Recurse -Force + } } - else { + if (-not (Test-Path $outputDir)) { New-Item -Path $outputDir -ItemType Directory | Out-Null } " Cleaned previous output directory [$outputDir]" @@ -85,8 +91,10 @@ task Compile -depends Clean { $functionsToExport = @() $sutLib = [System.IO.Path]::Combine($sut,'lib') $aliasesToExport = (. $sut\Aliases\PSGSuite.Aliases.ps1).Keys - $modDir = New-Item -Path $outputModDir -ItemType Directory -ErrorAction SilentlyContinue - New-Item -Path $outputModVerDir -ItemType Directory -ErrorAction SilentlyContinue | Out-Null + if ("$env:NoNugetRestore" -ne 'True') { + $modDir = New-Item -Path $outputModDir -ItemType Directory -ErrorAction SilentlyContinue + New-Item -Path $outputModVerDir -ItemType Directory -ErrorAction SilentlyContinue | Out-Null + } # Append items to psm1 Write-BuildLog 'Creating psm1...' @@ -99,11 +107,16 @@ task Compile -depends Clean { "$(Get-Content $_.FullName -Raw)`nExport-ModuleMember -Function '$($_.BaseName)'`n" | Add-Content -Path $psm1 -Encoding UTF8 $functionsToExport += $_.BaseName } - - New-Item -Path "$outputModVerDir\lib" -ItemType Directory -ErrorAction SilentlyContinue | Out-Null Invoke-CommandWithLog {Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue -Force -Verbose:$false} - Write-BuildLog "Installing NuGet dependencies..." - Invoke-CommandWithLog {Install-NuGetDependencies -Destination $outputModVerDir -AddlSearchString $NuGetSearchStrings -Verbose} + + if ("$env:NoNugetRestore" -ne 'True') { + New-Item -Path "$outputModVerDir\lib" -ItemType Directory -ErrorAction SilentlyContinue | Out-Null + Write-BuildLog "Installing NuGet dependencies..." + Invoke-CommandWithLog {Install-NuGetDependencies -Destination $outputModVerDir -AddlSearchString $NuGetSearchStrings -Verbose} + } + else { + Write-BuildLog "Skipping NuGet Restore due to `$env:NoNugetRestore = $env:NoNugetRestore" + } $aliasHashContents = (Get-Content "$sut\Aliases\PSGSuite.Aliases.ps1" -Raw).Trim() From 1c69af4f615ca07fe29a750cf95b20d55ee0aa5d Mon Sep 17 00:00:00 2001 From: Nate Ferrell Date: Fri, 31 May 2019 02:55:06 -0500 Subject: [PATCH 4/4] v2.28.0 - pushing up changes --- CHANGELOG.md | 51 +++++- .../Get-GSUserLicenseListPrivate.ps1 | 116 -------------- PSGSuite/Public/Calendar/Get-GSCalendar.ps1 | 25 ++- .../Public/Calendar/Get-GSCalendarACL.ps1 | 27 +++- .../Public/Calendar/Get-GSCalendarEvent.ps1 | 25 ++- .../Get-GSDataTransferApplication.ps1 | 27 +++- PSGSuite/Public/Drive/Add-GSDocContent.ps1 | 2 +- .../Public/Drive/Add-GSDrivePermission.ps1 | 2 +- PSGSuite/Public/Drive/Copy-GSDriveFile.ps1 | 2 +- PSGSuite/Public/Drive/Get-GSDrive.ps1 | 1 + PSGSuite/Public/Drive/Get-GSDriveFile.ps1 | 9 +- PSGSuite/Public/Drive/Get-GSDriveFileList.ps1 | 29 +++- .../Public/Drive/Get-GSDrivePermission.ps1 | 27 +++- PSGSuite/Public/Drive/New-GSDriveFile.ps1 | 2 +- PSGSuite/Public/Drive/Remove-GSDriveFile.ps1 | 2 +- .../Public/Drive/Remove-GSDrivePermission.ps1 | 2 +- PSGSuite/Public/Drive/Set-GSDocContent.ps1 | 2 +- .../Public/Drive/Start-GSDriveFileUpload.ps1 | 4 +- PSGSuite/Public/Drive/Update-GSDriveFile.ps1 | 57 +++++-- .../Public/Gmail/Get-GSGmailMessageList.ps1 | 27 +++- PSGSuite/Public/Groups/Get-GSGroup.ps1 | 28 +++- PSGSuite/Public/Groups/Get-GSGroupMember.ps1 | 27 +++- .../Public/Licensing/Get-GSUserLicense.ps1 | 148 ++++++++++++++---- .../Public/Reports/Get-GSActivityReport.ps1 | 1 + PSGSuite/Public/Reports/Get-GSUsageReport.ps1 | 1 + PSGSuite/Public/Resources/Get-GSResource.ps1 | 128 ++++++++++++--- .../Get-GSAdminRoleAssignment.ps1 | 86 +++++++--- PSGSuite/Public/Roles/Get-GSAdminRole.ps1 | 27 +++- .../Public/Security/Get-GSChromeOSDevice.ps1 | 40 +++-- .../Public/Security/Get-GSMobileDevice.ps1 | 72 +++++++-- .../Security/Update-GSChromeOSDevice.ps1 | 27 ++++ PSGSuite/Public/Tasks/Get-GSTask.ps1 | 27 +++- PSGSuite/Public/Tasks/Get-GSTasklist.ps1 | 27 +++- PSGSuite/Public/Users/Get-GSUser.ps1 | 29 +++- README.md | 61 +++++++- 35 files changed, 854 insertions(+), 314 deletions(-) delete mode 100644 PSGSuite/Private/ListPrivate/Get-GSUserLicenseListPrivate.ps1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 26967894..c96ed452 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,5 @@ -# Changelog - -* [Changelog](#changelog) - * [2.28.0 - 2019-05-31](#2280---2019-05-31) +* [PSGSuite - ChangeLog](#psgsuite---changelog) + * [2.28.0](#2280) * [2.27.0](#2270) * [2.26.4](#2264) * [2.26.3](#2263) @@ -88,25 +86,62 @@ *** -## 2.28.0 - 2019-05-31 +# PSGSuite - ChangeLog + +## 2.28.0 * [Issue #188](https://github.com/scrthq/PSGSuite/issues/188) * Added: `Get-GSDriveFile` now supports specifying a full file path. * Fixed: `Get-GSDriveFile` will now replace any special path characters in the filename with underscores * Added: The File object returned by `Get-GSDriveFile` will now include an additional `OutFilePath` property if the file is downloaded. This property will contain the full path to the downloaded file. * [Issue #190](https://github.com/scrthq/PSGSuite/issues/190) - * Fixed: `Fields` parameter on `Get-GSDriveFile` was not being honored. + * Fixed: `Fields` parameter on `Get-GSDriveFile` and `Update-GSDriveFile` were not being honored. +* [Issue #192](https://github.com/scrthq/PSGSuite/issues/192) + * Added: Parameters to `Update-GSDriveFile`: + * `CopyRequiresWriterPermission [switch]` + * `Starred [switch]` + * `Trashed [switch]` + * `WritersCanShare [switch]` +* [Issue #194](https://github.com/scrthq/PSGSuite/issues/194) + * Added: Parameters to `Update-GSChromeOSDevice`: + * `AnnotatedAssetId [string]` + * `AnnotatedLocation [string]` + * `AnnotatedUser [string]` + * `Notes [string]` * [Issue #195](https://github.com/scrthq/PSGSuite/issues/195) - * Added: `Limit` parameter with `First` alias to the following List functions: + * Added: `Limit` parameter with `First` alias to the following `List` functions: * `Get-GSActivityReport` + * `Get-GSAdminRole` + * `Get-GSAdminRoleAssignment` + * `Get-GSCalendar` + * `Get-GSCalendarAcl` + * `Get-GSCalendarEvent` + * `Get-GSChromeOSDevice` + * `Get-GSDataTransferApplication` * `Get-GSDrive` - * `Get-GSTeamDrive` + * `Get-GSDriveFileList` + * `Get-GSDrivePermission` + * `Get-GSGmailMessageList` + * `Get-GSGroup` + * `Get-GSGroupMember` + * `Get-GSMobileDevice` + * `Get-GSResource` + * `Get-GSTask` + * `Get-GSTaskList` + * `Get-GSUsageReport` + * `Get-GSUser` + * `Get-GSUserLicense` * [Issue #196](https://github.com/scrthq/PSGSuite/issues/196) * Fixed: `Get-GSTeamDrive` was not paginating through the results. +* [Issue #197](https://github.com/scrthq/PSGSuite/issues/197) + * Renamed: `Get-GSTeamDrive` has been changed to `Get-GSDrive`. `Get-GSTeamDrive` has been turned into an alias for `Get-GSDrive` to maintain backwards compatibility. + * Replaced: `SupportsTeamDrives = $true` with `SupportsAllDrives = $true` on all functions that have it. * Miscellaneous * Fixed: `Export-PSGSuiteConfig` is faster due to safely assuming that the P12Key and/or ClientSecrets values have already been pulled from the corresponding keys. * Fixed: Incomplete documentation for `Test-GSGroupMembership`. * Added: `UseDomainAdminAccess` switch parameter to `Get-GSTeamDrive` + * Removed: `Get-GSUserLicenseListPrivate` by rolling the `List` code into `Get-GSUserLicense` + * Removed: `Get-GSResourceListPrivate` by rolling the `List` code into `Get-GSResource` ## 2.27.0 diff --git a/PSGSuite/Private/ListPrivate/Get-GSUserLicenseListPrivate.ps1 b/PSGSuite/Private/ListPrivate/Get-GSUserLicenseListPrivate.ps1 deleted file mode 100644 index 4dbaf9e6..00000000 --- a/PSGSuite/Private/ListPrivate/Get-GSUserLicenseListPrivate.ps1 +++ /dev/null @@ -1,116 +0,0 @@ -function Get-GSUserLicenseListPrivate { - [cmdletbinding()] - Param - ( - [parameter(Mandatory = $false)] - [ValidateSet("Google-Apps","Google-Drive-storage","Google-Vault","Cloud-Identity","Cloud-Identity-Premium")] - [string[]] - $ProductID = @("Google-Apps","Google-Drive-storage","Google-Vault","Cloud-Identity","Cloud-Identity-Premium"), - [parameter(Mandatory = $false)] - [Alias("SkuId")] - [ValidateSet("Cloud-Identity","Cloud-Identity-Premium","Drive-Enterprise","G-Suite-Enterprise","Google-Apps-Unlimited","Google-Apps-For-Business","Google-Apps-For-Postini","Google-Apps-Lite","Google-Drive-storage-20GB","Google-Drive-storage-50GB","Google-Drive-storage-200GB","Google-Drive-storage-400GB","Google-Drive-storage-1TB","Google-Drive-storage-2TB","Google-Drive-storage-4TB","Google-Drive-storage-8TB","Google-Drive-storage-16TB","Google-Vault","Google-Vault-Former-Employee","1010020020","1010060001","1010010001","1010050001")] - [string] - $License, - [parameter(Mandatory = $false)] - [Alias("MaxResults")] - [ValidateRange(1,1000)] - [Int] - $PageSize = "1000" - ) - Begin { - $serviceParams = @{ - Scope = 'https://www.googleapis.com/auth/apps.licensing' - ServiceType = 'Google.Apis.Licensing.v1.LicensingService' - } - $service = New-GoogleService @serviceParams - if ($License) { - $ProductID = @{ - 'Cloud-Identity' = @('101001') # Cloud-Identity - '1010010001' = @('101001') # Cloud-Identity - 'Cloud-Identity-Premium' = @('101005') # Cloud-Identity-Premium - '1010050001' = @('101005') # Cloud-Identity-Premium - '1010020020' = @('Google-Apps') # G-Suite-Enterprise - '1010060001' = @('Google-Apps') # Drive-Enterprise - 'G-Suite-Enterprise' = @('Google-Apps') - 'Google-Apps-Unlimited' = @('Google-Apps') - 'Google-Apps-For-Business' = @('Google-Apps') - 'Google-Apps-For-Postini' = @('Google-Apps') - 'Google-Apps-Lite' = @('Google-Apps') - 'Google-Vault' = @('Google-Vault') - 'Google-Vault-Former-Employee' = @('Google-Vault') - 'Google-Drive-storage-20GB' = @('Google-Drive-storage') - 'Google-Drive-storage-50GB' = @('Google-Drive-storage') - 'Google-Drive-storage-200GB' = @('Google-Drive-storage') - 'Google-Drive-storage-400GB' = @('Google-Drive-storage') - 'Google-Drive-storage-1TB' = @('Google-Drive-storage') - 'Google-Drive-storage-2TB' = @('Google-Drive-storage') - 'Google-Drive-storage-4TB' = @('Google-Drive-storage') - 'Google-Drive-storage-8TB' = @('Google-Drive-storage') - 'Google-Drive-storage-16TB' = @('Google-Drive-storage') - }[$License] - } - $response = @() - } - Process { - try { - foreach ($prodId in $ProductID) { - switch ($prodId) { - "Cloud-Identity" { - $prodId = "101001" - } - "Cloud-Identity-Premium" { - $prodId = "101005" - } - } - if ($License) { - switch ($License) { - "G-Suite-Enterprise" { - $License = "1010020020" - } - "Drive-Enterprise" { - $License = "1010060001" - } - "Cloud-Identity" { - $License = "1010010001" - } - "Cloud-Identity-Premium" { - $License = "1010050001" - } - } - $request = $service.LicenseAssignments.ListForProductAndSku($prodId,$License,$Script:PSGSuite.Domain) - } - else { - $request = $service.LicenseAssignments.ListForProduct($prodId,$Script:PSGSuite.Domain) - } - if ($PageSize) { - $request.MaxResults = $PageSize - } - [int]$i = 1 - do { - $result = $request.Execute() - $response += $result.Items - $request.PageToken = $result.NextPageToken - [int]$retrieved = ($i + $result.Items.Count) - 1 - if ($License) { - Write-Verbose "Retrieved $retrieved licenses for product '$prodId' & sku '$License'..." - } - else { - Write-Verbose "Retrieved $retrieved licenses for product '$prodId'..." - } - [int]$i = $i + $result.Items.Count - } - until (!$result.NextPageToken) - } - Write-Verbose "Retrieved $($response.Count) total licenses" - return $response - } - catch { - if ($ErrorActionPreference -eq 'Stop') { - $PSCmdlet.ThrowTerminatingError($_) - } - else { - Write-Error $_ - } - } - } -} diff --git a/PSGSuite/Public/Calendar/Get-GSCalendar.ps1 b/PSGSuite/Public/Calendar/Get-GSCalendar.ps1 index ee928b9d..96b2af59 100644 --- a/PSGSuite/Public/Calendar/Get-GSCalendar.ps1 +++ b/PSGSuite/Public/Calendar/Get-GSCalendar.ps1 @@ -22,6 +22,9 @@ function Get-GSCalendar { .PARAMETER PageSize Maximum number of entries returned on one result page. The page size can never be larger than 250 entries. + .PARAMETER Limit + The maximum amount of results you want returned. Exclude or set to 0 to return all results + .PARAMETER ShowDeleted Whether to include deleted calendar list entries in the result. Optional. The default is False. @@ -58,6 +61,10 @@ function Get-GSCalendar { [Int] $PageSize = 250, [parameter(Mandatory = $false,ParameterSetName = "List")] + [Alias('First')] + [Int] + $Limit = 0, + [parameter(Mandatory = $false,ParameterSetName = "List")] [switch] $ShowDeleted, [parameter(Mandatory = $false,ParameterSetName = "List")] @@ -107,11 +114,14 @@ function Get-GSCalendar { $request.$key = $PSBoundParameters[$key] } } - if ($PageSize) { - $request.MaxResults = $PageSize + if ($Limit -gt 0 -and $PageSize -gt $Limit) { + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with first page" -f $PageSize,$Limit) + $PageSize = $Limit } + $request.MaxResults = $PageSize Write-Verbose "Getting Calendar List for user '$U'" [int]$i = 1 + $overLimit = $false do { $result = $request.Execute() $result.Items | Add-Member -MemberType NoteProperty -Name 'User' -Value $U -PassThru @@ -120,9 +130,18 @@ function Get-GSCalendar { } [int]$retrieved = ($i + $result.Items.Count) - 1 Write-Verbose "Retrieved $retrieved Calendars..." + if ($Limit -gt 0 -and $retrieved -eq $Limit) { + Write-Verbose "Limit reached: $Limit" + $overLimit = $true + } + elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { + $newPS = $Limit - $retrieved + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) + $request.MaxResults = $newPS + } [int]$i = $i + $result.Items.Count } - until (!$result.NextPageToken) + until ($overLimit -or !$result.NextPageToken) } catch { if ($ErrorActionPreference -eq 'Stop') { diff --git a/PSGSuite/Public/Calendar/Get-GSCalendarACL.ps1 b/PSGSuite/Public/Calendar/Get-GSCalendarACL.ps1 index e888e8e4..558cd693 100644 --- a/PSGSuite/Public/Calendar/Get-GSCalendarACL.ps1 +++ b/PSGSuite/Public/Calendar/Get-GSCalendarACL.ps1 @@ -22,6 +22,9 @@ function Get-GSCalendarAcl { .PARAMETER PageSize Maximum number of events returned on one result page. + .PARAMETER Limit + The maximum amount of results you want returned. Exclude or set to 0 to return all results + .EXAMPLE Get-GSCalendarACL -User me -CalendarID "primary" @@ -46,7 +49,11 @@ function Get-GSCalendarAcl { [parameter(Mandatory = $false, ParameterSetName = 'List')] [ValidateRange(1,2500)] [Int] - $PageSize = 2500 + $PageSize = 2500, + [parameter(Mandatory = $false, ParameterSetName = 'List')] + [Alias('First')] + [Int] + $Limit = 0 ) Process { foreach ($U in $User) { @@ -81,11 +88,14 @@ function Get-GSCalendarAcl { } } } - if ($PageSize) { - $request.MaxResults = $PageSize + if ($Limit -gt 0 -and $PageSize -gt $Limit) { + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with first page" -f $PageSize,$Limit) + $PageSize = $Limit } + $request.MaxResults = $PageSize Write-Verbose "Getting ACL List of calendar '$calId' for user '$U'" [int]$i = 1 + $overLimit = $false do { $result = $request.Execute() $result.Items | Add-Member -MemberType NoteProperty -Name 'User' -Value $U -PassThru | Add-Member -MemberType NoteProperty -Name 'CalendarId' -Value $calId -PassThru @@ -94,9 +104,18 @@ function Get-GSCalendarAcl { } [int]$retrieved = ($i + $result.Items.Count) - 1 Write-Verbose "Retrieved $retrieved Calendar ACLs..." + if ($Limit -gt 0 -and $retrieved -eq $Limit) { + Write-Verbose "Limit reached: $Limit" + $overLimit = $true + } + elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { + $newPS = $Limit - $retrieved + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) + $request.MaxResults = $newPS + } [int]$i = $i + $result.Items.Count } - until (!$result.NextPageToken) + until ($overLimit -or !$result.NextPageToken) } } } diff --git a/PSGSuite/Public/Calendar/Get-GSCalendarEvent.ps1 b/PSGSuite/Public/Calendar/Get-GSCalendarEvent.ps1 index 06933ec2..331e35df 100644 --- a/PSGSuite/Public/Calendar/Get-GSCalendarEvent.ps1 +++ b/PSGSuite/Public/Calendar/Get-GSCalendarEvent.ps1 @@ -32,6 +32,9 @@ function Get-GSCalendarEvent { .PARAMETER PageSize Maximum number of events returned on one result page. + .PARAMETER Limit + The maximum amount of results you want returned. Exclude or set to 0 to return all results + .PARAMETER ShowDeleted Whether to include deleted events (with status equals "cancelled") in the result. Cancelled instances of recurring events (but not the underlying recurring event) will still be included if showDeleted and singleEvents are both False. If showDeleted and singleEvents are both True, only single instances of deleted events (but not the underlying recurring events) are returned. @@ -82,6 +85,10 @@ function Get-GSCalendarEvent { [ValidateRange(1,2500)] [Int] $PageSize = 2500, + [parameter(Mandatory = $false,ParameterSetName = 'List')] + [Alias('First')] + [Int] + $Limit = 0, [parameter(Mandatory = $false,ParameterSetName = "List")] [switch] $ShowDeleted, @@ -169,9 +176,11 @@ function Get-GSCalendarEvent { } } } - if ($PageSize) { - $request.MaxResults = $PageSize + if ($Limit -gt 0 -and $PageSize -gt $Limit) { + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with first page" -f $PageSize,$Limit) + $PageSize = $Limit } + $request.MaxResults = $PageSize if ($Filter) { Write-Verbose "Getting all Calendar Events matching filter '$Filter' on calendar '$calId' for user '$U'" } @@ -179,6 +188,7 @@ function Get-GSCalendarEvent { Write-Verbose "Getting all Calendar Events on calendar '$calId' for user '$U'" } [int]$i = 1 + $overLimit = $false do { $result = $request.Execute() $result.Items | Add-Member -MemberType NoteProperty -Name 'User' -Value $U -PassThru | Add-Member -MemberType NoteProperty -Name 'CalendarId' -Value $calId -PassThru @@ -187,9 +197,18 @@ function Get-GSCalendarEvent { } [int]$retrieved = ($i + $result.Items.Count) - 1 Write-Verbose "Retrieved $retrieved Calendar Events..." + if ($Limit -gt 0 -and $retrieved -eq $Limit) { + Write-Verbose "Limit reached: $Limit" + $overLimit = $true + } + elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { + $newPS = $Limit - $retrieved + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) + $request.MaxResults = $newPS + } [int]$i = $i + $result.Items.Count } - until (!$result.NextPageToken) + until ($overLimit -or !$result.NextPageToken) } catch { if ($ErrorActionPreference -eq 'Stop') { diff --git a/PSGSuite/Public/Data Transfer/Get-GSDataTransferApplication.ps1 b/PSGSuite/Public/Data Transfer/Get-GSDataTransferApplication.ps1 index f2450f57..fc95fad3 100644 --- a/PSGSuite/Public/Data Transfer/Get-GSDataTransferApplication.ps1 +++ b/PSGSuite/Public/Data Transfer/Get-GSDataTransferApplication.ps1 @@ -14,6 +14,9 @@ Defaults to 500 (although it's typically a much smaller number for most Customers) + .PARAMETER Limit + The maximum amount of results you want returned. Exclude or set to 0 to return all results + .EXAMPLE Get-GSDataTransferApplication @@ -29,7 +32,11 @@ [parameter(Mandatory = $false)] [ValidateRange(1,500)] [Int] - $PageSize = 500 + $PageSize = 500, + [parameter(Mandatory = $false)] + [Alias('First')] + [Int] + $Limit = 0 ) Begin { $serviceParams = @{ @@ -49,12 +56,15 @@ else { $request = $service.Applications.List() $request.CustomerId = $Script:PSGSuite.CustomerID - if ($PageSize) { - $request.MaxResults = $PageSize + if ($Limit -gt 0 -and $PageSize -gt $Limit) { + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with first page" -f $PageSize,$Limit) + $PageSize = $Limit } + $request.MaxResults = $PageSize Write-Verbose "Getting all Data Transfer Applications" $response = @() [int]$i = 1 + $overLimit = $false do { $result = $request.Execute() $response += $result.Applications @@ -63,9 +73,18 @@ } [int]$retrieved = ($i + $result.Applications.Count) - 1 Write-Verbose "Retrieved $retrieved Data Transfer Applications..." + if ($Limit -gt 0 -and $retrieved -eq $Limit) { + Write-Verbose "Limit reached: $Limit" + $overLimit = $true + } + elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { + $newPS = $Limit - $retrieved + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) + $request.MaxResults = $newPS + } [int]$i = $i + $result.Applications.Count } - until (!$result.NextPageToken) + until ($overLimit -or !$result.NextPageToken) return $response } } diff --git a/PSGSuite/Public/Drive/Add-GSDocContent.ps1 b/PSGSuite/Public/Drive/Add-GSDocContent.ps1 index 642e81a9..03f0e912 100644 --- a/PSGSuite/Public/Drive/Add-GSDocContent.ps1 +++ b/PSGSuite/Public/Drive/Add-GSDocContent.ps1 @@ -69,7 +69,7 @@ function Add-GSDocContent { $request = $service.Files.Update($body,$FileId,$stream,$contentType) $request.QuotaUser = $User $request.ChunkSize = 512KB - $request.SupportsTeamDrives = $true + $request.SupportsAllDrives = $true Write-Verbose "Adding content to File '$FileID'" $request.Upload() | Out-Null } diff --git a/PSGSuite/Public/Drive/Add-GSDrivePermission.ps1 b/PSGSuite/Public/Drive/Add-GSDrivePermission.ps1 index 1b5b662a..227e3d63 100644 --- a/PSGSuite/Public/Drive/Add-GSDrivePermission.ps1 +++ b/PSGSuite/Public/Drive/Add-GSDrivePermission.ps1 @@ -179,7 +179,7 @@ function Add-GSDrivePermission { } } $request = $service.Permissions.Create($body,$FileId) - $request.SupportsTeamDrives = $true + $request.SupportsAllDrives = $true foreach ($key in $PSBoundParameters.Keys) { if ($request.PSObject.Properties.Name -contains $key -and $key -ne 'FileId') { $request.$key = $PSBoundParameters[$key] diff --git a/PSGSuite/Public/Drive/Copy-GSDriveFile.ps1 b/PSGSuite/Public/Drive/Copy-GSDriveFile.ps1 index 3c2bd3ec..778a69b7 100644 --- a/PSGSuite/Public/Drive/Copy-GSDriveFile.ps1 +++ b/PSGSuite/Public/Drive/Copy-GSDriveFile.ps1 @@ -113,7 +113,7 @@ function Copy-GSDriveFile { $body.Parents = [String[]]$Parents } $request = $service.Files.Copy($body,$FileID) - $request.SupportsTeamDrives = $true + $request.SupportsAllDrives = $true if ($fs) { $request.Fields = "$($fs -join ",")" } diff --git a/PSGSuite/Public/Drive/Get-GSDrive.ps1 b/PSGSuite/Public/Drive/Get-GSDrive.ps1 index f9db7c3e..af126379 100644 --- a/PSGSuite/Public/Drive/Get-GSDrive.ps1 +++ b/PSGSuite/Public/Drive/Get-GSDrive.ps1 @@ -110,6 +110,7 @@ function Get-GSDrive { [int]$retrieved = ($i + $result.Drives.Count) - 1 Write-Verbose "Retrieved $retrieved Shared Drives..." if ($Limit -gt 0 -and $retrieved -eq $Limit) { + Write-Verbose "Limit reached: $Limit" $overLimit = $true } elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { diff --git a/PSGSuite/Public/Drive/Get-GSDriveFile.ps1 b/PSGSuite/Public/Drive/Get-GSDriveFile.ps1 index d751b5c8..a524b632 100644 --- a/PSGSuite/Public/Drive/Get-GSDriveFile.ps1 +++ b/PSGSuite/Public/Drive/Get-GSDriveFile.ps1 @@ -21,7 +21,6 @@ function Get-GSDriveFile { The defined subset of fields to be returned Available values are: - * "Minimal" * "Standard" * "Full" * "Access" @@ -56,7 +55,7 @@ function Get-GSDriveFile { $OutFilePath, [parameter(Mandatory = $false,ParameterSetName = "Depth")] [Alias('Depth')] - [ValidateSet("Minimal","Standard","Full","Access")] + [ValidateSet("Standard","Full","Access")] [String] $Projection = "Full", [parameter(Mandatory = $false,ParameterSetName = "Fields")] @@ -68,7 +67,7 @@ function Get-GSDriveFile { $Force ) Begin { - if ($Projection) { + if ($PSCmdlet.ParameterSetName -eq 'Depth') { $fs = switch ($Projection) { Standard { @("createdTime","description","fileExtension","id","lastModifyingUser","modifiedTime","name","owners","parents","properties","version","webContentLink","webViewLink") @@ -81,7 +80,7 @@ function Get-GSDriveFile { } } } - elseif ($Fields) { + elseif ($PSBoundParameters.ContainsKey('Fields')) { $fs = $Fields } } @@ -102,7 +101,7 @@ function Get-GSDriveFile { foreach ($file in $FileId) { $backupPath = $null $request = $service.Files.Get($file) - $request.SupportsTeamDrives = $true + $request.SupportsAllDrives = $true if ($fs) { $request.Fields = $($fs -join ",") } diff --git a/PSGSuite/Public/Drive/Get-GSDriveFileList.ps1 b/PSGSuite/Public/Drive/Get-GSDriveFileList.ps1 index 5dfe76be..a4bebda4 100644 --- a/PSGSuite/Public/Drive/Get-GSDriveFileList.ps1 +++ b/PSGSuite/Public/Drive/Get-GSDriveFileList.ps1 @@ -40,6 +40,9 @@ function Get-GSDriveFileList { .PARAMETER PageSize The page size of the result set + .PARAMETER Limit + The maximum amount of results you want returned. Exclude or set to 0 to return all results + .EXAMPLE Get-GSDriveFileList joe @@ -85,7 +88,11 @@ function Get-GSDriveFileList { [Alias('MaxResults')] [ValidateRange(1,1000)] [Int] - $PageSize = "1000" + $PageSize = 1000, + [parameter(Mandatory = $false)] + [Alias('First')] + [Int] + $Limit = 0 ) Begin { if ($TeamDriveId) { @@ -121,10 +128,12 @@ function Get-GSDriveFileList { $service = New-GoogleService @serviceParams try { $request = $service.Files.List() - $request.SupportsTeamDrives = $true - if ($PageSize) { - $request.PageSize = $PageSize + $request.SupportsAllDrives = $true + if ($Limit -gt 0 -and $PageSize -gt $Limit) { + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with first page" -f $PageSize,$Limit) + $PageSize = $Limit } + $request.PageSize = $PageSize if ($Fields) { $request.Fields = "$($Fields -join ",")" } @@ -154,6 +163,7 @@ function Get-GSDriveFileList { } Write-Verbose $baseVerbose [int]$i = 1 + $overLimit = $false do { $result = $request.Execute() $result.Files | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru @@ -162,9 +172,18 @@ function Get-GSDriveFileList { } [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" + $overLimit = $true + } + elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { + $newPS = $Limit - $retrieved + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) + $request.PageSize = $newPS + } [int]$i = $i + $result.Files.Count } - until (!$result.NextPageToken) + until ($overLimit -or !$result.NextPageToken) } catch { if ($ErrorActionPreference -eq 'Stop') { diff --git a/PSGSuite/Public/Drive/Get-GSDrivePermission.ps1 b/PSGSuite/Public/Drive/Get-GSDrivePermission.ps1 index 2441c0bb..718e49e3 100644 --- a/PSGSuite/Public/Drive/Get-GSDrivePermission.ps1 +++ b/PSGSuite/Public/Drive/Get-GSDrivePermission.ps1 @@ -20,6 +20,9 @@ function Get-GSDrivePermission { .PARAMETER PageSize The page size of the result set + .PARAMETER Limit + The maximum amount of results you want returned. Exclude or set to 0 to return all results + .EXAMPLE Get-GSDrivePermission -FileId '1rhsAYTOB_vrpvfwImPmWy0TcVa2sgmQa_9u976' @@ -43,7 +46,11 @@ function Get-GSDrivePermission { [Alias('MaxResults')] [ValidateRange(1,100)] [Int] - $PageSize = "100" + $PageSize = 100, + [parameter(Mandatory = $false,ParameterSetName = "List")] + [Alias('First')] + [Int] + $Limit = 0 ) Process { if ($User -ceq 'me') { @@ -62,7 +69,7 @@ function Get-GSDrivePermission { if ($PermissionId) { foreach ($per in $PermissionId) { $request = $service.Permissions.Get($FileId,$per) - $request.SupportsTeamDrives = $true + $request.SupportsAllDrives = $true $request.Fields = "*" Write-Verbose "Getting Permission Id '$per' on File '$FileId' for user '$User'" $request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru | Add-Member -MemberType NoteProperty -Name 'FileId' -Value $FileId -PassThru @@ -70,11 +77,16 @@ function Get-GSDrivePermission { } else { $request = $service.Permissions.List($FileId) - $request.SupportsTeamDrives = $true + $request.SupportsAllDrives = $true + if ($Limit -gt 0 -and $PageSize -gt $Limit) { + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with first page" -f $PageSize,$Limit) + $PageSize = $Limit + } $request.PageSize = $PageSize $request.Fields = "*" Write-Verbose "Getting Permission list on File '$FileId' for user '$User'" [int]$i = 1 + $overLimit = $false do { $result = $request.Execute() $result.Permissions | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru | Add-Member -MemberType NoteProperty -Name 'FileId' -Value $FileId -PassThru @@ -83,6 +95,15 @@ function Get-GSDrivePermission { } [int]$retrieved = ($i + $result.Permissions.Count) - 1 Write-Verbose "Retrieved $retrieved Permissions..." + if ($Limit -gt 0 -and $retrieved -eq $Limit) { + Write-Verbose "Limit reached: $Limit" + $overLimit = $true + } + elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { + $newPS = $Limit - $retrieved + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) + $request.PageSize = $newPS + } [int]$i = $i + $result.Permissions.Count } until (!$result.NextPageToken) diff --git a/PSGSuite/Public/Drive/New-GSDriveFile.ps1 b/PSGSuite/Public/Drive/New-GSDriveFile.ps1 index e5fef55d..b379b61f 100644 --- a/PSGSuite/Public/Drive/New-GSDriveFile.ps1 +++ b/PSGSuite/Public/Drive/New-GSDriveFile.ps1 @@ -224,7 +224,7 @@ function New-GSDriveFile { $body.Parents = [String[]]$Parents } $request = $service.Files.Create($body) - $request.SupportsTeamDrives = $true + $request.SupportsAllDrives = $true if ($fs) { $request.Fields = $($fs -join ",") } diff --git a/PSGSuite/Public/Drive/Remove-GSDriveFile.ps1 b/PSGSuite/Public/Drive/Remove-GSDriveFile.ps1 index dc0908f7..b72386bb 100644 --- a/PSGSuite/Public/Drive/Remove-GSDriveFile.ps1 +++ b/PSGSuite/Public/Drive/Remove-GSDriveFile.ps1 @@ -48,7 +48,7 @@ function Remove-GSDriveFile { if ($PSCmdlet.ShouldProcess("Deleting File Id '$file' from user '$User'")) { Write-Verbose "Deleting File Id '$file' from user '$User'" $request = $service.Files.Delete($file) - $request.SupportsTeamDrives = $true + $request.SupportsAllDrives = $true $request.Execute() Write-Verbose "File Id '$file' successfully deleted from user '$User'" } diff --git a/PSGSuite/Public/Drive/Remove-GSDrivePermission.ps1 b/PSGSuite/Public/Drive/Remove-GSDrivePermission.ps1 index bbf46f94..dc697412 100644 --- a/PSGSuite/Public/Drive/Remove-GSDrivePermission.ps1 +++ b/PSGSuite/Public/Drive/Remove-GSDrivePermission.ps1 @@ -58,7 +58,7 @@ function Remove-GSDrivePermission { try { if ($PSCmdlet.ShouldProcess("Removing Drive Permission Id '$PermissionId' from FileId '$FileID'")) { $request = $service.Permissions.Delete($FileId,$PermissionId) - $request.SupportsTeamDrives = $true + $request.SupportsAllDrives = $true $request.Execute() Write-Verbose "Successfully removed Drive Permission Id '$PermissionId' from FileId '$FileID'" } diff --git a/PSGSuite/Public/Drive/Set-GSDocContent.ps1 b/PSGSuite/Public/Drive/Set-GSDocContent.ps1 index fadf3986..2b43bb84 100644 --- a/PSGSuite/Public/Drive/Set-GSDocContent.ps1 +++ b/PSGSuite/Public/Drive/Set-GSDocContent.ps1 @@ -68,7 +68,7 @@ function Set-GSDocContent { $request = $service.Files.Update($body,$FileId,$stream,$contentType) $request.QuotaUser = $User $request.ChunkSize = 512KB - $request.SupportsTeamDrives = $true + $request.SupportsAllDrives = $true Write-Verbose "Setting content for File '$FileID'" $request.Upload() | Out-Null $stream.Close() diff --git a/PSGSuite/Public/Drive/Start-GSDriveFileUpload.ps1 b/PSGSuite/Public/Drive/Start-GSDriveFileUpload.ps1 index b8b8ef69..b660718d 100644 --- a/PSGSuite/Public/Drive/Start-GSDriveFileUpload.ps1 +++ b/PSGSuite/Public/Drive/Start-GSDriveFileUpload.ps1 @@ -166,7 +166,7 @@ function Start-GSDriveFileUpload { $stream = New-Object 'System.IO.FileStream' $detPart.FullName,([System.IO.FileMode]::Open),([System.IO.FileAccess]::Read),([System.IO.FileShare]"Delete, ReadWrite") $request = $service.Files.Create($body,$stream,$contentType) $request.QuotaUser = $User - $request.SupportsTeamDrives = $true + $request.SupportsAllDrives = $true $request.ChunkSize = 512KB $upload = $request.UploadAsync() $task = $upload.ContinueWith([System.Action[System.Threading.Tasks.Task]] {if ($stream) { @@ -264,7 +264,7 @@ function Start-GSDriveFileUpload { $stream = New-Object 'System.IO.FileStream' $detPart.FullName,([System.IO.FileMode]::Open),([System.IO.FileAccess]::Read),([System.IO.FileShare]::Delete + [System.IO.FileShare]::ReadWrite) $request = $service.Files.Create($body,$stream,$contentType) $request.QuotaUser = $User - $request.SupportsTeamDrives = $true + $request.SupportsAllDrives = $true $request.ChunkSize = 512KB $upload = $request.UploadAsync() $task = $upload.ContinueWith([System.Action[System.Threading.Tasks.Task]] {$stream.Dispose()}) diff --git a/PSGSuite/Public/Drive/Update-GSDriveFile.ps1 b/PSGSuite/Public/Drive/Update-GSDriveFile.ps1 index 9b33df86..134e2132 100644 --- a/PSGSuite/Public/Drive/Update-GSDriveFile.ps1 +++ b/PSGSuite/Public/Drive/Update-GSDriveFile.ps1 @@ -53,6 +53,17 @@ function Update-GSDriveFile { .PARAMETER RemoveParents The parent Ids to remove + .PARAMETER CopyRequiresWriterPermission + Whether the options to copy, print, or download this file, should be disabled for readers and commenters. + + .PARAMETER Starred + Whether the user has starred the file. + + .PARAMETER Trashed + Whether the file has been trashed, either explicitly or from a trashed parent folder. + + Only the owner may trash a file, and other users cannot see files in the owner's trash. + .PARAMETER Projection The defined subset of fields to be returned @@ -84,14 +95,14 @@ function Update-GSDriveFile { ( [parameter(Mandatory = $true,Position = 0,ValueFromPipelineByPropertyName = $true)] [Alias('Id')] - [String] + [string] $FileId, [parameter(Mandatory = $false,Position = 1)] [ValidateScript( { Test-Path $_ })] - [String] + [string] $Path, [parameter(Mandatory = $false)] - [String] + [string] $Name, [parameter(Mandatory = $false)] [String] @@ -101,11 +112,23 @@ function Update-GSDriveFile { [string] $FolderColorRgb, [parameter(Mandatory = $false)] - [String[]] + [string[]] $AddParents, [parameter(Mandatory = $false)] [String[]] $RemoveParents, + [parameter(Mandatory = $false)] + [switch] + $CopyRequiresWriterPermission, + [parameter(Mandatory = $false)] + [switch] + $Starred, + [parameter(Mandatory = $false)] + [switch] + $Trashed, + [parameter(Mandatory = $false)] + [switch] + $WritersCanShare, [parameter(Mandatory = $false,ParameterSetName = "Depth")] [Alias('Depth')] [ValidateSet("Minimal","Standard","Full","Access")] @@ -147,7 +170,7 @@ function Update-GSDriveFile { PurpleRain = '#cd74e6' ToyEggplant = '#a47ae2' } - if ($Projection) { + if ($PSCmdlet.ParameterSetName -eq 'Depth') { $fs = switch ($Projection) { Standard { @("createdTime","description","fileExtension","id","lastModifyingUser","modifiedTime","name","owners","parents","properties","version","webContentLink","webViewLink") @@ -160,7 +183,7 @@ function Update-GSDriveFile { } } } - elseif ($Fields) { + elseif ($PSBoundParameters.ContainsKey('Fields')) { $fs = $Fields } } @@ -179,14 +202,18 @@ function Update-GSDriveFile { $service = New-GoogleService @serviceParams try { $body = New-Object 'Google.Apis.Drive.v3.Data.File' - if ($Name) { - $body.Name = [String]$Name - } - if ($Description) { - $body.Description = $Description - } - if ($FolderColorRgb) { - $body.FolderColorRgb = $ColorDictionary[$FolderColorRgb] + foreach ($prop in $PSBoundParameters.Keys | Where-Object { $body.PSObject.Properties.Name -contains $_ }) { + switch ($prop) { + Name { + $body.Name = [String]$Name + } + FolderColorRgb { + $body.FolderColorRgb = $ColorDictionary[$FolderColorRgb] + } + Default { + $body.$prop = $PSBoundParameters[$prop] + } + } } if ($PSBoundParameters.Keys -contains 'Path') { $ioFile = Get-Item $Path @@ -202,7 +229,7 @@ function Update-GSDriveFile { else { $request = $service.Files.Update($body,$FileId) } - $request.SupportsTeamDrives = $true + $request.SupportsAllDrives = $true if ($fs) { $request.Fields = $($fs -join ",") } diff --git a/PSGSuite/Public/Gmail/Get-GSGmailMessageList.ps1 b/PSGSuite/Public/Gmail/Get-GSGmailMessageList.ps1 index 8aa7ddf2..71e33c7a 100644 --- a/PSGSuite/Public/Gmail/Get-GSGmailMessageList.ps1 +++ b/PSGSuite/Public/Gmail/Get-GSGmailMessageList.ps1 @@ -28,6 +28,9 @@ function Get-GSGmailMessageList { .PARAMETER PageSize The page size of the result set + .PARAMETER Limit + The maximum amount of results you want returned. Exclude or set to 0 to return all results + .EXAMPLE Get-GSGmailMessageList -Filter "to:me","after:2017/12/25" -ExcludeChats @@ -58,7 +61,11 @@ function Get-GSGmailMessageList { [parameter(Mandatory = $false)] [ValidateRange(1,500)] [Int] - $PageSize = "500" + $PageSize = 500, + [parameter(Mandatory = $false)] + [Alias('First')] + [Int] + $Limit = 0 ) Process { try { @@ -99,9 +106,11 @@ function Get-GSGmailMessageList { } } } - if ($PageSize) { - $request.MaxResults = $PageSize + if ($Limit -gt 0 -and $PageSize -gt $Limit) { + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with first page" -f $PageSize,$Limit) + $PageSize = $Limit } + $request.MaxResults = $PageSize if ($Filter) { Write-Verbose "Getting all Messages matching filter '$Filter' for user '$U'" } @@ -109,6 +118,7 @@ function Get-GSGmailMessageList { Write-Verbose "Getting all Messages for user '$U'" } [int]$i = 1 + $overLimit = $false do { $result = $request.Execute() if ($result.Messages) { @@ -119,9 +129,18 @@ function Get-GSGmailMessageList { } [int]$retrieved = ($i + $result.Messages.Count) - 1 Write-Verbose "Retrieved $retrieved Messages..." + if ($Limit -gt 0 -and $retrieved -eq $Limit) { + Write-Verbose "Limit reached: $Limit" + $overLimit = $true + } + elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { + $newPS = $Limit - $retrieved + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) + $request.MaxResults = $newPS + } [int]$i = $i + $result.Messages.Count } - until (!$result.NextPageToken) + until ($overLimit -or !$result.NextPageToken) } } catch { diff --git a/PSGSuite/Public/Groups/Get-GSGroup.ps1 b/PSGSuite/Public/Groups/Get-GSGroup.ps1 index ef9d54c0..214719ed 100644 --- a/PSGSuite/Public/Groups/Get-GSGroup.ps1 +++ b/PSGSuite/Public/Groups/Get-GSGroup.ps1 @@ -26,6 +26,9 @@ Defaults to 200 + .PARAMETER Limit + The maximum amount of results you want returned. Exclude or set to 0 to return all results + .EXAMPLE Get-GSGroup -Where_IsAMember "joe@domain.com" @@ -74,7 +77,12 @@ [ValidateRange(1,200)] [Alias("MaxResults")] [Int] - $PageSize = "200" + $PageSize = 200, + [parameter(Mandatory = $false,ParameterSetName = "ListFilter")] + [parameter(Mandatory = $false,ParameterSetName = "ListWhereMember")] + [Alias('First')] + [Int] + $Limit = 0 ) Begin { $serviceParams = @{ @@ -142,11 +150,14 @@ $request.Customer = "my_customer" } } - if ($PageSize) { - $request.MaxResults = $PageSize + if ($Limit -gt 0 -and $PageSize -gt $Limit) { + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with first page" -f $PageSize,$Limit) + $PageSize = $Limit } + $request.MaxResults = $PageSize Write-Verbose $verbString [int]$i = 1 + $overLimit = $false do { $result = $request.Execute() if ($null -ne $result.GroupsValue) { @@ -155,9 +166,18 @@ $request.PageToken = $result.NextPageToken [int]$retrieved = ($i + $result.GroupsValue.Count) - 1 Write-Verbose "Retrieved $retrieved groups..." + if ($Limit -gt 0 -and $retrieved -eq $Limit) { + Write-Verbose "Limit reached: $Limit" + $overLimit = $true + } + elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { + $newPS = $Limit - $retrieved + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) + $request.MaxResults = $newPS + } [int]$i = $i + $result.GroupsValue.Count } - until (!$result.NextPageToken) + until ($overLimit -or !$result.NextPageToken) } catch { if ($ErrorActionPreference -eq 'Stop') { diff --git a/PSGSuite/Public/Groups/Get-GSGroupMember.ps1 b/PSGSuite/Public/Groups/Get-GSGroupMember.ps1 index 0c3e232f..6f815a2c 100644 --- a/PSGSuite/Public/Groups/Get-GSGroupMember.ps1 +++ b/PSGSuite/Public/Groups/Get-GSGroupMember.ps1 @@ -18,6 +18,9 @@ function Get-GSGroupMember { .PARAMETER PageSize Page size of the result set + .PARAMETER Limit + The maximum amount of results you want returned. Exclude or set to 0 to return all results + .EXAMPLE Get-GSGroupMember "admins@domain.com" -Roles Owner,Manager @@ -42,7 +45,11 @@ function Get-GSGroupMember { [parameter(Mandatory=$false,ParameterSetName = "List")] [ValidateRange(1,200)] [Int] - $PageSize="200" + $PageSize = 200, + [parameter(Mandatory=$false,ParameterSetName = "List")] + [Alias('First')] + [Int] + $Limit = 0 ) Begin { $serviceParams = @{ @@ -85,9 +92,11 @@ function Get-GSGroupMember { $Id = "$($Id)@$($Script:PSGSuite.Domain)" } $request = $service.Members.List($Id) - if ($PageSize) { - $request.MaxResults = $PageSize + if ($Limit -gt 0 -and $PageSize -gt $Limit) { + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with first page" -f $PageSize,$Limit) + $PageSize = $Limit } + $request.MaxResults = $PageSize if ($Roles) { Write-Verbose "Getting all members of group '$Id' in the following role(s): $($Roles -join ',')" $request.Roles = "$($Roles -join ',')" @@ -96,6 +105,7 @@ function Get-GSGroupMember { Write-Verbose "Getting all members of group '$Id'" } [int]$i = 1 + $overLimit = $false do { $result = $request.Execute() if ($null -ne $result.MembersValue) { @@ -104,9 +114,18 @@ function Get-GSGroupMember { $request.PageToken = $result.NextPageToken [int]$retrieved = ($i + $result.MembersValue.Count) - 1 Write-Verbose "Retrieved $retrieved members..." + if ($Limit -gt 0 -and $retrieved -eq $Limit) { + Write-Verbose "Limit reached: $Limit" + $overLimit = $true + } + elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { + $newPS = $Limit - $retrieved + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) + $request.MaxResults = $newPS + } [int]$i = $i + $result.MembersValue.Count } - until (!$result.NextPageToken) + until ($overLimit -or !$result.NextPageToken) } catch { if ($ErrorActionPreference -eq 'Stop') { diff --git a/PSGSuite/Public/Licensing/Get-GSUserLicense.ps1 b/PSGSuite/Public/Licensing/Get-GSUserLicense.ps1 index 5c2d43ff..f33f6a5c 100644 --- a/PSGSuite/Public/Licensing/Get-GSUserLicense.ps1 +++ b/PSGSuite/Public/Licensing/Get-GSUserLicense.ps1 @@ -18,6 +18,9 @@ function Get-GSUserLicense { .PARAMETER PageSize The page size of the result set + .PARAMETER Limit + The maximum amount of results you want returned. Exclude or set to 0 to return all results + .EXAMPLE Get-GSUserLicense @@ -45,39 +48,41 @@ function Get-GSUserLicense { [Alias("MaxResults")] [ValidateRange(1,1000)] [Int] - $PageSize = "1000" + $PageSize = 1000, + [parameter(Mandatory = $false,ParameterSetName = "List")] + [Alias('First')] + [Int] + $Limit = 0 ) Begin { - if ($PSCmdlet.ParameterSetName -eq 'Get') { - $serviceParams = @{ - Scope = 'https://www.googleapis.com/auth/apps.licensing' - ServiceType = 'Google.Apis.Licensing.v1.LicensingService' - } - $service = New-GoogleService @serviceParams - $productHash = @{ - 'Cloud-Identity' = '101001' # Cloud-Identity - '1010010001' = '101001' # Cloud-Identity - 'Cloud-Identity-Premium' = '101005' # Cloud-Identity-Premium - '1010050001' = '101005' # Cloud-Identity-Premium - '1010020020' = 'Google-Apps' # G-Suite-Enterprise - '1010060001' = 'Google-Apps' # Drive-Enterprise - 'G-Suite-Enterprise' = 'Google-Apps' - 'Google-Apps-Unlimited' = 'Google-Apps' - 'Google-Apps-For-Business' = 'Google-Apps' - 'Google-Apps-For-Postini' = 'Google-Apps' - 'Google-Apps-Lite' = 'Google-Apps' - 'Google-Vault' = 'Google-Vault' - 'Google-Vault-Former-Employee' = 'Google-Vault' - 'Google-Drive-storage-20GB' = 'Google-Drive-storage' - 'Google-Drive-storage-50GB' = 'Google-Drive-storage' - 'Google-Drive-storage-200GB' = 'Google-Drive-storage' - 'Google-Drive-storage-400GB' = 'Google-Drive-storage' - 'Google-Drive-storage-1TB' = 'Google-Drive-storage' - 'Google-Drive-storage-2TB' = 'Google-Drive-storage' - 'Google-Drive-storage-4TB' = 'Google-Drive-storage' - 'Google-Drive-storage-8TB' = 'Google-Drive-storage' - 'Google-Drive-storage-16TB' = 'Google-Drive-storage' - } + $serviceParams = @{ + Scope = 'https://www.googleapis.com/auth/apps.licensing' + ServiceType = 'Google.Apis.Licensing.v1.LicensingService' + } + $service = New-GoogleService @serviceParams + $productHash = @{ + 'Cloud-Identity' = '101001' # Cloud-Identity + '1010010001' = '101001' # Cloud-Identity + 'Cloud-Identity-Premium' = '101005' # Cloud-Identity-Premium + '1010050001' = '101005' # Cloud-Identity-Premium + '1010020020' = 'Google-Apps' # G-Suite-Enterprise + '1010060001' = 'Google-Apps' # Drive-Enterprise + 'G-Suite-Enterprise' = 'Google-Apps' + 'Google-Apps-Unlimited' = 'Google-Apps' + 'Google-Apps-For-Business' = 'Google-Apps' + 'Google-Apps-For-Postini' = 'Google-Apps' + 'Google-Apps-Lite' = 'Google-Apps' + 'Google-Vault' = 'Google-Vault' + 'Google-Vault-Former-Employee' = 'Google-Vault' + 'Google-Drive-storage-20GB' = 'Google-Drive-storage' + 'Google-Drive-storage-50GB' = 'Google-Drive-storage' + 'Google-Drive-storage-200GB' = 'Google-Drive-storage' + 'Google-Drive-storage-400GB' = 'Google-Drive-storage' + 'Google-Drive-storage-1TB' = 'Google-Drive-storage' + 'Google-Drive-storage-2TB' = 'Google-Drive-storage' + 'Google-Drive-storage-4TB' = 'Google-Drive-storage' + 'Google-Drive-storage-8TB' = 'Google-Drive-storage' + 'Google-Drive-storage-16TB' = 'Google-Drive-storage' } } Process { @@ -147,7 +152,86 @@ function Get-GSUserLicense { } } List { - Get-GSUserLicenseListPrivate @PSBoundParameters + if ($License) { + $ProductID = $productHash[$License] + } + $total = 0 + try { + $overLimit = $false + foreach ($prodId in $ProductID) { + if (-not $overLimit) { + Write-Verbose "Retrieving licenses for product '$prodId'" + switch ($prodId) { + "Cloud-Identity" { + $prodId = "101001" + } + "Cloud-Identity-Premium" { + $prodId = "101005" + } + } + if ($License) { + switch ($License) { + "G-Suite-Enterprise" { + $License = "1010020020" + } + "Drive-Enterprise" { + $License = "1010060001" + } + "Cloud-Identity" { + $License = "1010010001" + } + "Cloud-Identity-Premium" { + $License = "1010050001" + } + } + $request = $service.LicenseAssignments.ListForProductAndSku($prodId,$License,$Script:PSGSuite.Domain) + } + else { + $request = $service.LicenseAssignments.ListForProduct($prodId,$Script:PSGSuite.Domain) + } + if ($Limit -gt 0 -and $PageSize -gt $Limit) { + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with first page" -f $PageSize,$Limit) + $PageSize = $Limit + } + $request.MaxResults = $PageSize + [int]$i = 1 + $overLimit = $false + do { + $result = $request.Execute() + $result.Items + $total += $result.Items.Count + $request.PageToken = $result.NextPageToken + [int]$retrieved = ($i + $result.Items.Count) - 1 + if ($License) { + Write-Verbose "Retrieved $retrieved licenses for product '$prodId' & sku '$License'..." + } + else { + Write-Verbose "Retrieved $retrieved licenses for product '$prodId'..." + } + if ($Limit -gt 0 -and $total -eq $Limit) { + Write-Verbose "Limit reached: $Limit" + $overLimit = $true + } + elseif ($Limit -gt 0 -and ($total + $PageSize) -gt $Limit) { + $newPS = $Limit - $total + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) + $request.MaxResults = $newPS + } + [int]$i = $i + $result.Items.Count + } + until ($overLimit -or !$result.NextPageToken) + } + } + Write-Verbose "Retrieved $total total licenses" + } + catch { + if ($ErrorActionPreference -eq 'Stop') { + $PSCmdlet.ThrowTerminatingError($_) + } + else { + Write-Error $_ + } + } } } } diff --git a/PSGSuite/Public/Reports/Get-GSActivityReport.ps1 b/PSGSuite/Public/Reports/Get-GSActivityReport.ps1 index 9fd0dfea..b1faa3af 100644 --- a/PSGSuite/Public/Reports/Get-GSActivityReport.ps1 +++ b/PSGSuite/Public/Reports/Get-GSActivityReport.ps1 @@ -131,6 +131,7 @@ function Get-GSActivityReport { [int]$retrieved = ($i + $result.Items.Count) - 1 Write-Verbose "Retrieved $retrieved events..." if ($Limit -gt 0 -and $retrieved -eq $Limit) { + Write-Verbose "Limit reached: $Limit" $overLimit = $true } elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { diff --git a/PSGSuite/Public/Reports/Get-GSUsageReport.ps1 b/PSGSuite/Public/Reports/Get-GSUsageReport.ps1 index aeae5857..bae1ae6f 100644 --- a/PSGSuite/Public/Reports/Get-GSUsageReport.ps1 +++ b/PSGSuite/Public/Reports/Get-GSUsageReport.ps1 @@ -203,6 +203,7 @@ function Get-GSUsageReport { [int]$retrieved = ($i + $result.UsageReportsValue.Count) - 1 Write-Verbose "Retrieved $retrieved entities for this report..." if ($Limit -gt 0 -and $retrieved -eq $Limit) { + Write-Verbose "Limit reached: $Limit" $overLimit = $true } elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { diff --git a/PSGSuite/Public/Resources/Get-GSResource.ps1 b/PSGSuite/Public/Resources/Get-GSResource.ps1 index d424267d..599e63df 100644 --- a/PSGSuite/Public/Resources/Get-GSResource.ps1 +++ b/PSGSuite/Public/Resources/Get-GSResource.ps1 @@ -2,13 +2,13 @@ function Get-GSResource { <# .SYNOPSIS Gets Calendar Resources (Calendars, Buildings & Features supported) - + .DESCRIPTION Gets Calendar Resources (Calendars, Buildings & Features supported) - + .PARAMETER Id If Id is provided, gets the Resource by Id - + .PARAMETER Resource The Resource Type to List @@ -16,18 +16,21 @@ function Get-GSResource { * "Calendars": resource calendars (legacy and new - i.e. conference rooms) * "Buildings": new Building Resources (i.e. "Building A" or "North Campus") * "Features": new Feature Resources (i.e. "Video Conferencing" or "Projector") - + .PARAMETER Filter String query used to filter results. Should be of the form "field operator value" where field can be any of supported fields and operators can be any of supported operations. Operators include '=' for exact match and ':' for prefix match or HAS match where applicable. For prefix match, the value should always be followed by a *. Supported fields include generatedResourceName, name, buildingId, featureInstances.feature.name. For example buildingId=US-NYC-9TH AND featureInstances.feature.name:Phone. PowerShell filter syntax here is supported as "best effort". Please use Google's filter operators and syntax to ensure best results - + .PARAMETER OrderBy Field(s) to sort results by in either ascending or descending order. Supported fields include resourceId, resourceName, capacity, buildingId, and floorName. - + .PARAMETER PageSize Page size of the result set - + + .PARAMETER Limit + The maximum amount of results you want returned. Exclude or set to 0 to return all results + .EXAMPLE Get-GSResource -Resource Buildings @@ -54,15 +57,31 @@ function Get-GSResource { [ValidateRange(1,500)] [Alias("MaxResults")] [Int] - $PageSize = "500" + $PageSize = 500, + [parameter(Mandatory = $false,ParameterSetName = "List")] + [Alias('First')] + [Int] + $Limit = 0 ) Begin { - if ($PSCmdlet.ParameterSetName -eq 'Get') { - $serviceParams = @{ - Scope = 'https://www.googleapis.com/auth/admin.directory.resource.calendar' - ServiceType = 'Google.Apis.Admin.Directory.directory_v1.DirectoryService' - } - $service = New-GoogleService @serviceParams + if ($MyInvocation.InvocationName -eq 'Get-GSCalendarResourceList') { + $Resource = 'Calendars' + } + $propHash = @{ + Calendars = 'Items' + Buildings = 'BuildingsValue' + Features = 'FeaturesValue' + } + $serviceParams = @{ + Scope = 'https://www.googleapis.com/auth/admin.directory.resource.calendar' + ServiceType = 'Google.Apis.Admin.Directory.directory_v1.DirectoryService' + } + $service = New-GoogleService @serviceParams + $customerId = if ($Script:PSGSuite.CustomerID) { + $Script:PSGSuite.CustomerID + } + else { + 'my_customer' } } Process { @@ -71,8 +90,8 @@ function Get-GSResource { foreach ($I in $Id) { try { Write-Verbose "Getting Resource $Resource Id '$I'" - $request = $service.Resources.$Resource.Get($(if($Script:PSGSuite.CustomerID){$Script:PSGSuite.CustomerID}else{'my_customer'}),$I) - $request.Execute() | Add-Member -MemberType NoteProperty -Name 'Id' -Value $I -PassThru | Add-Member -MemberType NoteProperty -Name 'Resource' -Value $Resource -PassThru | Add-Member -MemberType ScriptMethod -Name ToString -Value {$this.Id} -PassThru -Force + $request = $service.Resources.$Resource.Get($customerId,$I) + $request.Execute() | Add-Member -MemberType NoteProperty -Name 'Id' -Value $I -PassThru | Add-Member -MemberType NoteProperty -Name 'Resource' -Value $Resource -PassThru | Add-Member -MemberType ScriptMethod -Name ToString -Value { $this.Id } -PassThru -Force } catch { if ($ErrorActionPreference -eq 'Stop') { @@ -85,8 +104,81 @@ function Get-GSResource { } } List { - Get-GSResourceListPrivate @PSBoundParameters + try { + $request = $service.Resources.$Resource.List($customerId) + if ($Limit -gt 0 -and $PageSize -gt $Limit) { + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with first page" -f $PageSize,$Limit) + $PageSize = $Limit + } + $request.MaxResults = $PageSize + if ($Resource -eq 'Calendars') { + if ($OrderBy) { + $request.OrderBy = "$($OrderBy -join ", ")" + } + if ($Filter) { + if ($Filter -eq '*') { + $Filter = "" + } + else { + $Filter = "$($Filter -join " ")" + } + $Filter = $Filter -replace " -eq ","=" -replace " -like ",":" -replace " -match ",":" -replace " -contains ",":" -creplace "'True'","True" -creplace "'False'","False" + $request.Query = $Filter.Trim() + Write-Verbose "Getting Resource $Resource matching filter: `"$($Filter.Trim())`"" + } + else { + Write-Verbose "Getting all Resource $Resource" + } + } + else { + Write-Verbose "Getting all Resource $Resource" + } + [int]$i = 1 + $overLimit = $false + do { + $result = $request.Execute() + $result.$($propHash[$Resource]) | ForEach-Object { + $obj = $_ + $_Id = switch ($Resource) { + Calendars { + $obj.ResourceId + } + Buildings { + $obj.BuildingId + } + Features { + $obj.Name + } + } + $_ | Add-Member -MemberType NoteProperty -Name 'Id' -Value $_Id -PassThru | Add-Member -MemberType NoteProperty -Name 'Resource' -Value $Resource -PassThru | Add-Member -MemberType ScriptMethod -Name ToString -Value { $this.Id } -PassThru -Force + } + if ($result.NextPageToken) { + $request.PageToken = $result.NextPageToken + } + [int]$retrieved = ($i + $result.$($propHash[$Resource]).Count) - 1 + Write-Verbose "Retrieved $retrieved resources..." + if ($Limit -gt 0 -and $retrieved -eq $Limit) { + Write-Verbose "Limit reached: $Limit" + $overLimit = $true + } + elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { + $newPS = $Limit - $retrieved + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) + $request.MaxResults = $newPS + } + [int]$i = $i + $result.$($propHash[$Resource]).Count + } + until ($overLimit -or !$result.NextPageToken) + } + catch { + if ($ErrorActionPreference -eq 'Stop') { + $PSCmdlet.ThrowTerminatingError($_) + } + else { + Write-Error $_ + } + } } } } -} \ No newline at end of file +} diff --git a/PSGSuite/Public/RoleAssignments/Get-GSAdminRoleAssignment.ps1 b/PSGSuite/Public/RoleAssignments/Get-GSAdminRoleAssignment.ps1 index cfd8eed5..d27b42b0 100644 --- a/PSGSuite/Public/RoleAssignments/Get-GSAdminRoleAssignment.ps1 +++ b/PSGSuite/Public/RoleAssignments/Get-GSAdminRoleAssignment.ps1 @@ -24,6 +24,9 @@ function Get-GSAdminRoleAssignment { .PARAMETER PageSize Page size of the result set + .PARAMETER Limit + The maximum amount of results you want returned. Exclude or set to 0 to return all results + .EXAMPLE Get-GSAdminRoleAssignment @@ -52,7 +55,12 @@ function Get-GSAdminRoleAssignment { [ValidateRange(1,100)] [Alias("MaxResults")] [Int] - $PageSize + $PageSize = 100, + [parameter(Mandatory = $false,ParameterSetName = "ListUserKey")] + [parameter(Mandatory = $false,ParameterSetName = "ListRoleId")] + [Alias('First')] + [Int] + $Limit = 0 ) Begin { $serviceParams = @{ @@ -88,34 +96,48 @@ function Get-GSAdminRoleAssignment { } Default { [int]$i = 1 + $overLimit = $false Write-Verbose "Getting Admin Role Assignment List" $baseRequest = $service.RoleAssignments.List($customerId) - if ($PSBoundParameters.Keys -contains 'PageSize') { - $baseRequest.MaxResults = $PSBoundParameters['PageSize'] + if ($Limit -gt 0 -and $PageSize -gt $Limit) { + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with first page" -f $PageSize,$Limit) + $PageSize = $Limit } + $baseRequest.MaxResults = $PageSize if ($PSBoundParameters.Keys -contains 'RoleId' -or $PSBoundParameters.Keys -contains 'UserKey') { switch ($PSBoundParameters.Keys) { RoleId { foreach ($Role in $RoleId) { - try { - $request = $baseRequest - $request.RoleId = $Role - do { - $result = $request.Execute() - $result.Items | Add-Member -MemberType NoteProperty -Name 'Filter' -Value ([PSCustomObject]@{RoleId = $Role}) -PassThru - $request.PageToken = $result.NextPageToken - [int]$retrieved = ($i + $result.Items.Count) - 1 - Write-Verbose "Retrieved $retrieved role assignments..." - [int]$i = $i + $result.Items.Count - } - until (!$result.NextPageToken) - } - catch { - if ($ErrorActionPreference -eq 'Stop') { - $PSCmdlet.ThrowTerminatingError($_) + if (-not $overLimit) { + try { + $request = $baseRequest + $request.RoleId = $Role + do { + $result = $request.Execute() + $result.Items | Add-Member -MemberType NoteProperty -Name 'Filter' -Value ([PSCustomObject]@{RoleId = $Role}) -PassThru + $request.PageToken = $result.NextPageToken + [int]$retrieved = ($i + $result.Items.Count) - 1 + Write-Verbose "Retrieved $retrieved role assignments..." + if ($Limit -gt 0 -and $retrieved -eq $Limit) { + Write-Verbose "Limit reached: $Limit" + $overLimit = $true + } + elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { + $newPS = $Limit - $retrieved + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) + $request.MaxResults = $newPS + } + [int]$i = $i + $result.Items.Count + } + until ($overLimit -or !$result.NextPageToken) } - else { - Write-Error $_ + catch { + if ($ErrorActionPreference -eq 'Stop') { + $PSCmdlet.ThrowTerminatingError($_) + } + else { + Write-Error $_ + } } } } @@ -143,9 +165,18 @@ function Get-GSAdminRoleAssignment { $request.PageToken = $result.NextPageToken [int]$retrieved = ($i + $result.Items.Count) - 1 Write-Verbose "Retrieved $retrieved role assignments..." + if ($Limit -gt 0 -and $retrieved -eq $Limit) { + Write-Verbose "Limit reached: $Limit" + $overLimit = $true + } + elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { + $newPS = $Limit - $retrieved + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) + $request.MaxResults = $newPS + } [int]$i = $i + $result.Items.Count } - until (!$result.NextPageToken) + until ($overLimit -or !$result.NextPageToken) } catch { if ($ErrorActionPreference -eq 'Stop') { @@ -168,9 +199,18 @@ function Get-GSAdminRoleAssignment { $request.PageToken = $result.NextPageToken [int]$retrieved = ($i + $result.Items.Count) - 1 Write-Verbose "Retrieved $retrieved role assignments..." + if ($Limit -gt 0 -and $retrieved -eq $Limit) { + Write-Verbose "Limit reached: $Limit" + $overLimit = $true + } + elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { + $newPS = $Limit - $retrieved + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) + $request.MaxResults = $newPS + } [int]$i = $i + $result.Items.Count } - until (!$result.NextPageToken) + until ($overLimit -or !$result.NextPageToken) } catch { if ($ErrorActionPreference -eq 'Stop') { diff --git a/PSGSuite/Public/Roles/Get-GSAdminRole.ps1 b/PSGSuite/Public/Roles/Get-GSAdminRole.ps1 index 5c39393e..017ed3ae 100644 --- a/PSGSuite/Public/Roles/Get-GSAdminRole.ps1 +++ b/PSGSuite/Public/Roles/Get-GSAdminRole.ps1 @@ -14,6 +14,9 @@ function Get-GSAdminRole { .PARAMETER PageSize Page size of the result set + .PARAMETER Limit + The maximum amount of results you want returned. Exclude or set to 0 to return all results + .EXAMPLE Get-GSAdminRole @@ -35,7 +38,11 @@ function Get-GSAdminRole { [ValidateRange(1,100)] [Alias("MaxResults")] [Int] - $PageSize + $PageSize = 100, + [parameter(Mandatory = $false,ParameterSetName = "List")] + [Alias('First')] + [Int] + $Limit = 0 ) Begin { $serviceParams = @{ @@ -73,19 +80,31 @@ function Get-GSAdminRole { try { Write-Verbose "Getting Admin Role List" $request = $service.Roles.List($customerId) - if ($PSBoundParameters.Keys -contains 'PageSize') { - $request.MaxResults = $PSBoundParameters['PageSize'] + if ($Limit -gt 0 -and $PageSize -gt $Limit) { + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with first page" -f $PageSize,$Limit) + $PageSize = $Limit } + $request.MaxResults = $PageSize [int]$i = 1 + $overLimit = $false do { $result = $request.Execute() $result.Items $request.PageToken = $result.NextPageToken [int]$retrieved = ($i + $result.Items.Count) - 1 Write-Verbose "Retrieved $retrieved roles..." + if ($Limit -gt 0 -and $retrieved -eq $Limit) { + Write-Verbose "Limit reached: $Limit" + $overLimit = $true + } + elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { + $newPS = $Limit - $retrieved + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) + $request.MaxResults = $newPS + } [int]$i = $i + $result.Items.Count } - until (!$result.NextPageToken) + until ($overLimit -or !$result.NextPageToken) } catch { if ($ErrorActionPreference -eq 'Stop') { diff --git a/PSGSuite/Public/Security/Get-GSChromeOSDevice.ps1 b/PSGSuite/Public/Security/Get-GSChromeOSDevice.ps1 index 7e33e419..692e6ed7 100644 --- a/PSGSuite/Public/Security/Get-GSChromeOSDevice.ps1 +++ b/PSGSuite/Public/Security/Get-GSChromeOSDevice.ps1 @@ -27,6 +27,9 @@ .PARAMETER PageSize Page size of the result set + .PARAMETER Limit + The maximum amount of results you want returned. Exclude or set to 0 to return all results + .PARAMETER OrderBy Device property to use for sorting results. @@ -74,7 +77,11 @@ [ValidateRange(1,100)] [Alias('MaxResults')] [Int] - $PageSize = "100", + $PageSize = 100, + [parameter(Mandatory = $false,ParameterSetName = "List")] + [Alias('First')] + [Int] + $Limit = 0, [parameter(Mandatory = $false,ParameterSetName = "List")] [ValidateSet("annotatedLocation","annotatedUser","lastSync","notes","serialNumber","status","supportEndDate")] [String] @@ -120,6 +127,11 @@ } List { $request = $service.Chromeosdevices.List($customerId) + if ($Limit -gt 0 -and $PageSize -gt $Limit) { + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with first page" -f $PageSize,$Limit) + $PageSize = $Limit + } + $request.MaxResults = $PageSize if ($PSBoundParameters.Keys -contains 'Filter') { Write-Verbose "Getting Chrome OS Device list for filter '$Filter'" $request.Query = $PSBoundParameters['Filter'] @@ -127,19 +139,14 @@ else { Write-Verbose "Getting Chrome OS Device list" } - foreach ($key in $PSBoundParameters.Keys | Where-Object {$_ -ne 'Filter'}) { - switch ($key) { - PageSize { - $request.MaxResults = $PSBoundParameters[$key] - } - default { - if ($request.PSObject.Properties.Name -contains $key) { - $request.$key = $PSBoundParameters[$key] - } - } + + foreach ($key in $PSBoundParameters.Keys | Where-Object {$_ -notin @('PageSize','Filter')}) { + if ($request.PSObject.Properties.Name -contains $key) { + $request.$key = $PSBoundParameters[$key] } } [int]$i = 1 + $overLimit = $false do { $result = $request.Execute() $result.Chromeosdevices @@ -148,9 +155,18 @@ } [int]$retrieved = ($i + $result.Chromeosdevices.Count) - 1 Write-Verbose "Retrieved $retrieved Chrome OS Devices..." + if ($Limit -gt 0 -and $retrieved -eq $Limit) { + Write-Verbose "Limit reached: $Limit" + $overLimit = $true + } + elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { + $newPS = $Limit - $retrieved + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) + $request.MaxResults = $newPS + } [int]$i = $i + $result.Chromeosdevices.Count } - until (!$result.NextPageToken) + until ($overLimit -or !$result.NextPageToken) } } } diff --git a/PSGSuite/Public/Security/Get-GSMobileDevice.ps1 b/PSGSuite/Public/Security/Get-GSMobileDevice.ps1 index 56ba4fa3..4b901e32 100644 --- a/PSGSuite/Public/Security/Get-GSMobileDevice.ps1 +++ b/PSGSuite/Public/Security/Get-GSMobileDevice.ps1 @@ -24,6 +24,9 @@ .PARAMETER PageSize Page size of the result set + .PARAMETER Limit + The maximum amount of results you want returned. Exclude or set to 0 to return all results + .PARAMETER OrderBy Device property to use for sorting results. @@ -69,7 +72,11 @@ [parameter(Mandatory = $false)] [ValidateRange(1,1000)] [Int] - $PageSize = "1000", + $PageSize = 1000, + [parameter(Mandatory = $false)] + [Alias('First')] + [Int] + $Limit = 0, [parameter(Mandatory = $false)] [ValidateSet("deviceId","email","lastSync","model","name","os","status","type")] [String] @@ -85,10 +92,23 @@ ServiceType = 'Google.Apis.Admin.Directory.directory_v1.DirectoryService' } $service = New-GoogleService @serviceParams + $customerId = if ($Script:PSGSuite.CustomerID) { + $Script:PSGSuite.CustomerID + } + else { + "my_customer" + } } Process { try { - $request = $service.Mobiledevices.List($Script:PSGSuite.CustomerID) + $request = $service.Mobiledevices.List($customerId) + if ($Limit -gt 0 -and $PageSize -gt $Limit) { + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with first page" -f $PageSize,$Limit) + $PageSize = $Limit + } + $request.MaxResults = $PageSize + [int]$i = 1 + $overLimit = $false switch ($PSCmdlet.ParameterSetName) { User { if ($User) { @@ -102,57 +122,75 @@ $Filter = "email:`"$U`"" $request.Query = $Filter Write-Verbose "Getting Mobile Device list for User '$U'" - $response = @() - [int]$i = 1 do { $result = $request.Execute() - $response += $result.Mobiledevices + $result.Mobiledevices if ($result.NextPageToken) { $request.PageToken = $result.NextPageToken } [int]$retrieved = ($i + $result.Mobiledevices.Count) - 1 Write-Verbose "Retrieved $retrieved Mobile Devices..." + if ($Limit -gt 0 -and $retrieved -eq $Limit) { + Write-Verbose "Limit reached: $Limit" + $overLimit = $true + } + elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { + $newPS = $Limit - $retrieved + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) + $request.MaxResults = $newPS + } [int]$i = $i + $result.Mobiledevices.Count } - until (!$result.NextPageToken) - return $response + until ($overLimit -or !$result.NextPageToken) } } else { Write-Verbose "Getting Mobile Device list for customer '$($script:PSGSuite.CustomerID)'" - $response = @() - [int]$i = 1 do { $result = $request.Execute() - $response += $result.Mobiledevices + $result.Mobiledevices if ($result.NextPageToken) { $request.PageToken = $result.NextPageToken } [int]$retrieved = ($i + $result.Mobiledevices.Count) - 1 Write-Verbose "Retrieved $retrieved Mobile Devices..." + if ($Limit -gt 0 -and $retrieved -eq $Limit) { + Write-Verbose "Limit reached: $Limit" + $overLimit = $true + } + elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { + $newPS = $Limit - $retrieved + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) + $request.MaxResults = $newPS + } [int]$i = $i + $result.Mobiledevices.Count } - until (!$result.NextPageToken) - return $response + until ($overLimit -or !$result.NextPageToken) } } Query { $request.Query = $Filter Write-Verbose "Getting Mobile Device list for filter '$Filter'" - $response = @() - [int]$i = 1 do { $result = $request.Execute() - $response += $result.Mobiledevices + $result.Mobiledevices if ($result.NextPageToken) { $request.PageToken = $result.NextPageToken } [int]$retrieved = ($i + $result.Mobiledevices.Count) - 1 Write-Verbose "Retrieved $retrieved Mobile Devices..." + if ($Limit -gt 0 -and $retrieved -eq $Limit) { + Write-Verbose "Limit reached: $Limit" + $overLimit = $true + } + elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { + $newPS = $Limit - $retrieved + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) + $request.MaxResults = $newPS + } [int]$i = $i + $result.Mobiledevices.Count } - until (!$result.NextPageToken) - return $response + until ($overLimit -or !$result.NextPageToken) } } } diff --git a/PSGSuite/Public/Security/Update-GSChromeOSDevice.ps1 b/PSGSuite/Public/Security/Update-GSChromeOSDevice.ps1 index 570302c1..e7366ab9 100644 --- a/PSGSuite/Public/Security/Update-GSChromeOSDevice.ps1 +++ b/PSGSuite/Public/Security/Update-GSChromeOSDevice.ps1 @@ -29,6 +29,18 @@ function Update-GSChromeOSDevice { * "retiring_device": Use if you're reselling, donating, or permanently removing the device from use. * "same_model_replacement": Use if a hardware issue was encountered on a device and it is being replaced with the same model or a like-model replacement from a repair vendor / manufacturer. + .PARAMETER AnnotatedAssetId + The asset identifier as noted by an administrator or specified during enrollment. + + .PARAMETER AnnotatedLocation + The address or location of the device as noted by the administrator. Maximum length is 200 characters. Empty values are allowed. + + .PARAMETER AnnotatedUser + The user of the device as noted by the administrator. Maximum length is 100 characters. Empty values are allowed. + + .PARAMETER Notes + Notes about this device added by the administrator. This property can be searched with the list method's query parameter. Maximum length is 500 characters. Empty values are allowed. + .PARAMETER OrgUnitPath Full path of the target organizational unit or its ID that you would like to move the device to. @@ -55,6 +67,21 @@ function Update-GSChromeOSDevice { $DeprovisionReason, [parameter(Mandatory = $false)] [String] + $AnnotatedAssetId, + [parameter(Mandatory = $false)] + [AllowNull()] + [String] + $AnnotatedLocation, + [parameter(Mandatory = $false)] + [AllowNull()] + [String] + $AnnotatedUser, + [parameter(Mandatory = $false)] + [AllowNull()] + [String] + $Notes, + [parameter(Mandatory = $false)] + [String] $OrgUnitPath ) diff --git a/PSGSuite/Public/Tasks/Get-GSTask.ps1 b/PSGSuite/Public/Tasks/Get-GSTask.ps1 index cca7729c..e5474d3d 100644 --- a/PSGSuite/Public/Tasks/Get-GSTask.ps1 +++ b/PSGSuite/Public/Tasks/Get-GSTask.ps1 @@ -22,6 +22,9 @@ function Get-GSTask { .PARAMETER PageSize Page size of the result set + .PARAMETER Limit + The maximum amount of results you want returned. Exclude or set to 0 to return all results + .EXAMPLE Get-GSTasklist @@ -76,7 +79,11 @@ function Get-GSTask { [ValidateRange(1,100)] [Alias("MaxResults")] [Int] - $PageSize + $PageSize = 100, + [parameter(Mandatory = $false,ParameterSetName = "List")] + [Alias('First')] + [Int] + $Limit = 0 ) Process { if ($User -ceq 'me') { @@ -126,19 +133,31 @@ function Get-GSTask { } } } - if ($PSBoundParameters.Keys -contains 'PageSize') { - $request.MaxResults = $PSBoundParameters['PageSize'] + if ($Limit -gt 0 -and $PageSize -gt $Limit) { + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with first page" -f $PageSize,$Limit) + $PageSize = $Limit } + $request.MaxResults = $PageSize [int]$i = 1 + $overLimit = $false do { $result = $request.Execute() $result.Items | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru $request.PageToken = $result.NextPageToken [int]$retrieved = ($i + $result.Items.Count) - 1 Write-Verbose "Retrieved $retrieved Tasks..." + if ($Limit -gt 0 -and $retrieved -eq $Limit) { + Write-Verbose "Limit reached: $Limit" + $overLimit = $true + } + elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { + $newPS = $Limit - $retrieved + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) + $request.MaxResults = $newPS + } [int]$i = $i + $result.Items.Count } - until (!$result.NextPageToken) + until ($overLimit -or !$result.NextPageToken) } catch { if ($ErrorActionPreference -eq 'Stop') { diff --git a/PSGSuite/Public/Tasks/Get-GSTasklist.ps1 b/PSGSuite/Public/Tasks/Get-GSTasklist.ps1 index cf3734f5..2e3bd36f 100644 --- a/PSGSuite/Public/Tasks/Get-GSTasklist.ps1 +++ b/PSGSuite/Public/Tasks/Get-GSTasklist.ps1 @@ -19,6 +19,9 @@ function Get-GSTasklist { .PARAMETER PageSize Page size of the result set + .PARAMETER Limit + The maximum amount of results you want returned. Exclude or set to 0 to return all results + .EXAMPLE Get-GSTasklist @@ -46,7 +49,11 @@ function Get-GSTasklist { [ValidateRange(1,100)] [Alias("MaxResults")] [Int] - $PageSize + $PageSize = 100, + [parameter(Mandatory = $false,ParameterSetName = "List")] + [Alias('First')] + [Int] + $Limit = 0 ) Process { if ($User -ceq 'me') { @@ -83,19 +90,31 @@ function Get-GSTasklist { try { Write-Verbose "Getting all Tasklists for user '$User'" $request = $service.Tasklists.List() - if ($PSBoundParameters.Keys -contains 'PageSize') { - $request.MaxResults = $PSBoundParameters['PageSize'] + if ($Limit -gt 0 -and $PageSize -gt $Limit) { + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with first page" -f $PageSize,$Limit) + $PageSize = $Limit } + $request.MaxResults = $PageSize [int]$i = 1 + $overLimit = $false do { $result = $request.Execute() $result.Items | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru $request.PageToken = $result.NextPageToken [int]$retrieved = ($i + $result.Items.Count) - 1 Write-Verbose "Retrieved $retrieved Tasklists..." + if ($Limit -gt 0 -and $retrieved -eq $Limit) { + Write-Verbose "Limit reached: $Limit" + $overLimit = $true + } + elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { + $newPS = $Limit - $retrieved + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) + $request.MaxResults = $newPS + } [int]$i = $i + $result.Items.Count } - until (!$result.NextPageToken) + until ($overLimit -or !$result.NextPageToken) } catch { if ($ErrorActionPreference -eq 'Stop') { diff --git a/PSGSuite/Public/Users/Get-GSUser.ps1 b/PSGSuite/Public/Users/Get-GSUser.ps1 index c65ea884..102f289f 100644 --- a/PSGSuite/Public/Users/Get-GSUser.ps1 +++ b/PSGSuite/Public/Users/Get-GSUser.ps1 @@ -59,6 +59,9 @@ function Get-GSUser { .PARAMETER PageSize Page size of the result set + .PARAMETER Limit + The maximum amount of results you want returned. Exclude or set to 0 to return all results + .PARAMETER OrderBy Property to use for sorting results. @@ -106,7 +109,7 @@ function Get-GSUser { [parameter(Mandatory = $false,ParameterSetName = "List")] [Alias("Query")] [String[]] - $Filter, + $Filter = '*', [parameter(Mandatory = $false,ParameterSetName = "List")] [String] $Domain, @@ -139,7 +142,11 @@ function Get-GSUser { [ValidateRange(1,500)] [Alias("MaxResults")] [Int] - $PageSize = "500", + $PageSize = 500, + [parameter(Mandatory = $false,ParameterSetName = "List")] + [Alias('First')] + [Int] + $Limit = 0, [parameter(Mandatory = $false,ParameterSetName = "List")] [ValidateSet("Email","GivenName","FamilyName")] [String] @@ -207,9 +214,11 @@ function Get-GSUser { $verbScope = "customer 'my_customer'" $request.Customer = "my_customer" } - if ($PageSize) { - $request.MaxResults = $PageSize + if ($Limit -gt 0 -and $PageSize -gt $Limit) { + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with first page" -f $PageSize,$Limit) + $PageSize = $Limit } + $request.MaxResults = $PageSize foreach ($prop in $PSBoundParameters.Keys | Where-Object {$_ -in @('OrderBy','SortOrder','CustomFieldMask','ShowDeleted','ViewType')}) { $request.$prop = $PSBoundParameters[$prop] } @@ -237,6 +246,7 @@ function Get-GSUser { } $response = New-Object System.Collections.ArrayList [int]$i = 1 + $overLimit = $false do { $result = $request.Execute() if ($result.UsersValue) { @@ -248,9 +258,18 @@ function Get-GSUser { $request.PageToken = $result.NextPageToken [int]$retrieved = ($i + $result.UsersValue.Count) - 1 Write-Verbose "Retrieved $retrieved users..." + if ($Limit -gt 0 -and $retrieved -eq $Limit) { + Write-Verbose "Limit reached: $Limit" + $overLimit = $true + } + elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { + $newPS = $Limit - $retrieved + Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) + $request.MaxResults = $newPS + } [int]$i = $i + $result.UsersValue.Count } - until (!$result.NextPageToken) + until ($overLimit -or !$result.NextPageToken) if ($SearchScope -ne "Subtree") { if (!$SearchBase) { $SearchBase = "/" diff --git a/README.md b/README.md index 5ef22bca..45aea23f 100644 --- a/README.md +++ b/README.md @@ -143,12 +143,57 @@ Update-GSSheetValue Export-GSSheet [Full CHANGELOG here](https://github.com/scrthq/PSGSuite/blob/master/CHANGELOG.md) -#### 2.27.0 - -* [Issue #185](https://github.com/scrthq/PSGSuite/issues/185) - * Fixed: `Get-GSGroup -Where_IsAMember $member` no longer errors. -* [Issue #186](https://github.com/scrthq/PSGSuite/issues/186) - * Added: `Test-GSGroupMembership` to map to the [hasMember method](https://developers.google.com/admin-sdk/directory/v1/reference/members/hasMember). +#### 2.28.0 + +* [Issue #188](https://github.com/scrthq/PSGSuite/issues/188) + * Added: `Get-GSDriveFile` now supports specifying a full file path. + * Fixed: `Get-GSDriveFile` will now replace any special path characters in the filename with underscores + * Added: The File object returned by `Get-GSDriveFile` will now include an additional `OutFilePath` property if the file is downloaded. This property will contain the full path to the downloaded file. +* [Issue #190](https://github.com/scrthq/PSGSuite/issues/190) + * Fixed: `Fields` parameter on `Get-GSDriveFile` and `Update-GSDriveFile` were not being honored. +* [Issue #192](https://github.com/scrthq/PSGSuite/issues/192) + * Added: Parameters to `Update-GSDriveFile`: + * `CopyRequiresWriterPermission [switch]` + * `Starred [switch]` + * `Trashed [switch]` + * `WritersCanShare [switch]` +* [Issue #194](https://github.com/scrthq/PSGSuite/issues/194) + * Added: Parameters to `Update-GSChromeOSDevice`: + * `AnnotatedAssetId [string]` + * `AnnotatedLocation [string]` + * `AnnotatedUser [string]` + * `Notes [string]` +* [Issue #195](https://github.com/scrthq/PSGSuite/issues/195) + * Added: `Limit` parameter with `First` alias to the following `List` functions: + * `Get-GSActivityReport` + * `Get-GSAdminRole` + * `Get-GSAdminRoleAssignment` + * `Get-GSCalendar` + * `Get-GSCalendarAcl` + * `Get-GSCalendarEvent` + * `Get-GSChromeOSDevice` + * `Get-GSDataTransferApplication` + * `Get-GSDrive` + * `Get-GSDriveFileList` + * `Get-GSDrivePermission` + * `Get-GSGmailMessageList` + * `Get-GSGroup` + * `Get-GSGroupMember` + * `Get-GSMobileDevice` + * `Get-GSResource` + * `Get-GSTask` + * `Get-GSTaskList` + * `Get-GSUsageReport` + * `Get-GSUser` + * `Get-GSUserLicense` +* [Issue #196](https://github.com/scrthq/PSGSuite/issues/196) + * Fixed: `Get-GSTeamDrive` was not paginating through the results. +* [Issue #197](https://github.com/scrthq/PSGSuite/issues/197) + * Renamed: `Get-GSTeamDrive` has been changed to `Get-GSDrive`. `Get-GSTeamDrive` has been turned into an alias for `Get-GSDrive` to maintain backwards compatibility. + * Replaced: `SupportsTeamDrives = $true` with `SupportsAllDrives = $true` on all functions that have it. * Miscellaneous - * Improved build process to auto-update NuGet dependencies. - * Added new private function `Resolve-Email` to convert a name-part or the case-sensitive `me` to the full email address accordingly. + * Fixed: `Export-PSGSuiteConfig` is faster due to safely assuming that the P12Key and/or ClientSecrets values have already been pulled from the corresponding keys. + * Fixed: Incomplete documentation for `Test-GSGroupMembership`. + * Added: `UseDomainAdminAccess` switch parameter to `Get-GSTeamDrive` + * Removed: `Get-GSUserLicenseListPrivate` by rolling the `List` code into `Get-GSUserLicense` + * Removed: `Get-GSResourceListPrivate` by rolling the `List` code into `Get-GSResource`