Skip to content

Commit

Permalink
!deploy v2.6.2 add profile retrieval functions for Drive and Gmail
Browse files Browse the repository at this point in the history
## 2.6.2

* Added: `Get-GSGmailProfile` and `Get-GSDriveProfile` to pull down information for a user's Gmail or Drive account.
  • Loading branch information
scrthq committed May 18, 2018
2 parents c99edfe + 3dab8ca commit 16e55a7
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<!-- TOC -->

- [Changelog](#changelog)
- [2.6.2](#262)
- [2.6.1](#261)
- [2.6.0](#260)
- [2.5.4](#254)
Expand Down Expand Up @@ -31,6 +32,10 @@

<!-- /TOC -->

## 2.6.2

* Added: `Get-GSGmailProfile` and `Get-GSDriveProfile` to pull down information for a user's Gmail or Drive account.

## 2.6.1

* Fixed: `Add-GSDrivePermission` error messages stating FileId is ReadOnly. ([Issue #47](https://github.com/scrthq/PSGSuite/issues/47))
Expand Down
2 changes: 1 addition & 1 deletion PSGSuite/PSGSuite.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'PSGSuite.psm1'

# Version number of this module.
ModuleVersion = '2.6.1'
ModuleVersion = '2.6.2'

# ID used to uniquely identify this module
GUID = '9d751152-e83e-40bb-a6db-4c329092aaec'
Expand Down
75 changes: 75 additions & 0 deletions PSGSuite/Public/Drive/Get-GSDriveProfile.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
function Get-GSDriveProfile {
<#
.SYNOPSIS
Gets Drive profile for the user
.DESCRIPTION
Gets Drive profile for the user
.PARAMETER User
The user to get profile of
Defaults to the AdminEmail user
.EXAMPLE
Get-GSDriveProfile
Gets the Drive profile of the AdminEmail user
#>
[cmdletbinding()]
Param
(
[parameter(Mandatory = $false,Position = 0,ValueFromPipelineByPropertyName = $true)]
[Alias('Owner','PrimaryEmail','UserKey','Mail')]
[string]
$User = $Script:PSGSuite.AdminEmail,
[parameter(Mandatory = $false,Position = 1)]
[ValidateSet('AppInstalled','ExportFormats','FolderColorPalette','ImportFormats','Kind','MaxImportSizes','MaxUploadSize','StorageQuota','TeamDriveThemes','User')]
[string[]]
$Fields = @('AppInstalled','ExportFormats','FolderColorPalette','ImportFormats','Kind','MaxImportSizes','MaxUploadSize','StorageQuota','TeamDriveThemes','User')
)
Begin {
$fieldDict = @{
AppInstalled = 'appInstalled'
ExportFormats = 'exportFormats'
FolderColorPalette = 'folderColorPalette'
ImportFormats = 'importFormats'
Kind = 'kind'
MaxImportSizes = 'maxImportSizes'
MaxUploadSize = 'maxUploadSize'
StorageQuota = 'storageQuota'
TeamDriveThemes = 'teamDriveThemes'
User = 'user'
}
}
Process {
foreach ($U in $User) {
if ($U -ceq 'me') {
$U = $Script:PSGSuite.AdminEmail
}
elseif ($U -notlike "*@*.*") {
$U = "$($U)@$($Script:PSGSuite.Domain)"
}
$serviceParams = @{
Scope = 'https://www.googleapis.com/auth/drive'
ServiceType = 'Google.Apis.Drive.v3.DriveService'
User = $U
}
$service = New-GoogleService @serviceParams
try {
$request = $service.About.Get()
$request.Fields = "$(($Fields | ForEach-Object {$fieldDict[$_]}) -join ",")"
Write-Verbose "Getting Drive profile for user '$U'"
$request.Execute()
}
catch {
if ($ErrorActionPreference -eq 'Stop') {
$PSCmdlet.ThrowTerminatingError($_)
}
else {
Write-Error $_
}
}
}
}
}
57 changes: 57 additions & 0 deletions PSGSuite/Public/Gmail/Get-GSGmailProfile.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
function Get-GSGmailProfile {
<#
.SYNOPSIS
Gets Gmail profile for the user
.DESCRIPTION
Gets Gmail profile for the user
.PARAMETER User
The user to get profile of
Defaults to the AdminEmail user
.EXAMPLE
Get-GSGmailProfile
Gets the Gmail profile of the AdminEmail user
#>
[cmdletbinding()]
Param
(
[parameter(Mandatory = $false,Position = 0,ValueFromPipelineByPropertyName = $true)]
[Alias("PrimaryEmail","UserKey","Mail")]
[ValidateNotNullOrEmpty()]
[String[]]
$User = $Script:PSGSuite.AdminEmail
)
Process {
foreach ($U in $User) {
try {
if ($U -ceq 'me') {
$U = $Script:PSGSuite.AdminEmail
}
elseif ($U -notlike "*@*.*") {
$U = "$($U)@$($Script:PSGSuite.Domain)"
}
$serviceParams = @{
Scope = 'https://mail.google.com'
ServiceType = 'Google.Apis.Gmail.v1.GmailService'
User = $U
}
$service = New-GoogleService @serviceParams
$request = $service.Users.GetProfile($U)
Write-Verbose "Getting Gmail profile for user '$U'"
$request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $U -PassThru
}
catch {
if ($ErrorActionPreference -eq 'Stop') {
$PSCmdlet.ThrowTerminatingError($_)
}
else {
Write-Error $_
}
}
}
}
}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ Update-GSSheetValue Export-GSSheet

### Most recent changes

#### 2.6.2

* Added: `Get-GSGmailProfile` and `Get-GSDriveProfile` to pull down information for a user's Gmail or Drive account.

#### 2.6.1

* Fixed: `Add-GSDrivePermission` error messages stating FileId is ReadOnly. ([Issue #47](https://github.com/scrthq/PSGSuite/issues/47))
Expand Down

0 comments on commit 16e55a7

Please sign in to comment.