-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
!deploy v2.6.2 add profile retrieval functions for Drive and Gmail
## 2.6.2 * Added: `Get-GSGmailProfile` and `Get-GSDriveProfile` to pull down information for a user's Gmail or Drive account.
- Loading branch information
Showing
5 changed files
with
142 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 $_ | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 $_ | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters