Skip to content

Commit

Permalink
updates for #185 and #186
Browse files Browse the repository at this point in the history
  • Loading branch information
scrthq committed May 15, 2019
1 parent a64d1f8 commit 3283bf2
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 98 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

* [Changelog](#changelog)
* [2.27.0](#2270)
* [2.26.4](#2264)
* [2.26.3](#2263)
* [2.26.2](#2262)
Expand Down Expand Up @@ -86,6 +87,16 @@

***

## 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).
* 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.

## 2.26.4

* [Issue #177](https://github.com/scrthq/PSGSuite/issues/177) - _Thanks, [@WJurecki](https://github.com/WJurecki)!_
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.26.4'
ModuleVersion = '2.27.0'

# ID used to uniquely identify this module
GUID = '9d751152-e83e-40bb-a6db-4c329092aaec'
Expand Down
20 changes: 20 additions & 0 deletions PSGSuite/Private/Resolve-Email.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function Resolve-Email {
[CmdletBinding()]
Param (
[parameter(Mandatory,Position = 0,ValueFromPipeline,ValueFromPipelineByPropertyName)]
[Ref[]]
$Email
)
Process {
foreach ($e in $Email) {
if ( -not ($e.value -as [decimal])) {
if ($e.value -ceq 'me') {
$e.value = $Script:PSGSuite.AdminEmail
}
elseif ($e.value -notlike "*@*.*") {
$e.value = "$($e.value)@$($Script:PSGSuite.Domain)"
}
}
}
}
}
20 changes: 10 additions & 10 deletions PSGSuite/Public/Groups/Add-GSGroupMember.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function Add-GSGroupMember {
[String]
$Identity,
[parameter(Mandatory = $true,ValueFromPipelineByPropertyName = $true,Position = 1)]
[Alias("PrimaryEmail","UserKey","Mail","User","UserEmail")]
[Alias("PrimaryEmail","UserKey","Mail","User","UserEmail","Members")]
[ValidateNotNullOrEmpty()]
[String[]]
$Member,
Expand All @@ -53,8 +53,8 @@ function Add-GSGroupMember {
$Identity = "$($Identity)@$($Script:PSGSuite.Domain)"
}
$groupObj = Get-GSGroup -Group $Identity -Verbose:$false
try {
foreach ($U in $Member) {
foreach ($U in $Member) {
try {
if ($U -notlike "*@*.*") {
$U = "$($U)@$($Script:PSGSuite.Domain)"
}
Expand All @@ -65,13 +65,13 @@ function Add-GSGroupMember {
$request = $service.Members.Insert($body,$groupObj.Id)
$request.Execute() | Add-Member -MemberType NoteProperty -Name 'Group' -Value $Identity -PassThru
}
}
catch {
if ($ErrorActionPreference -eq 'Stop') {
$PSCmdlet.ThrowTerminatingError($_)
}
else {
Write-Error $_
catch {
if ($ErrorActionPreference -eq 'Stop') {
$PSCmdlet.ThrowTerminatingError($_)
}
else {
Write-Error $_
}
}
}
}
Expand Down
53 changes: 25 additions & 28 deletions PSGSuite/Public/Groups/Get-GSGroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,30 @@
Gets the IT HelpDesk group by name using PowerShell syntax. PowerShell syntax is supported as a best effort, please refer to the Group Search documentation from Google for exact syntax.
#>
[OutputType('Google.Apis.Admin.Directory.directory_v1.Data.Group')]
[cmdletbinding(DefaultParameterSetName = "List")]
[cmdletbinding(DefaultParameterSetName = "ListFilter")]
Param
(
[parameter(Mandatory = $true,Position = 0,ValueFromPipeline = $true,ValueFromPipelineByPropertyName = $true,ParameterSetName = "Get")]
[Alias("Email")]
[ValidateNotNullOrEmpty()]
[String[]]
$Group,
[parameter(Mandatory = $false,ParameterSetName = "List")]
[parameter(Mandatory = $false,ParameterSetName = "ListFilter")]
[Alias('Query')]
[string]
$Filter,
[parameter(Mandatory = $false,ParameterSetName = "List")]
[parameter(Mandatory = $false,ParameterSetName = "ListWhereMember")]
[Alias('UserKey')]
[String]
$Where_IsAMember,
[parameter(Mandatory = $false,ParameterSetName = "List")]
[parameter(Mandatory = $false,ParameterSetName = "ListFilter")]
[string]
$Domain,
[parameter(Mandatory = $false,ParameterSetName = "Get")]
[String[]]
$Fields,
[parameter(Mandatory = $false,ParameterSetName = "List")]
[parameter(Mandatory = $false,ParameterSetName = "ListFilter")]
[parameter(Mandatory = $false,ParameterSetName = "ListWhereMember")]
[ValidateRange(1,200)]
[Alias("MaxResults")]
[Int]
Expand All @@ -82,13 +84,11 @@
$service = New-GoogleService @serviceParams
}
Process {
switch ($PSCmdlet.ParameterSetName) {
switch -Regex ($PSCmdlet.ParameterSetName) {
Get {
foreach ($G in $Group) {
try {
if ($G -notlike "*@*.*") {
$G = "$($G)@$($Script:PSGSuite.Domain)"
}
Resolve-Email ([ref]$G)
Write-Verbose "Getting group '$G'"
$request = $service.Groups.Get($G)
if ($Fields) {
Expand All @@ -106,21 +106,16 @@
}
}
}
List {
'List.*' {
$verbString = "Getting all G Suite Groups"
try {
$request = $service.Groups.List()
if ($PSBoundParameters.Keys -contains 'Where_IsAMember') {
if ($Where_IsAMember -ceq "me") {
$Where_IsAMember = $Script:PSGSuite.AdminEmail
}
elseif ($Where_IsAMember -notlike "*@*.*") {
$Where_IsAMember = "$($Where_IsAMember)@$($Script:PSGSuite.Domain)"
}
Resolve-Email ([ref]$Where_IsAMember)
$verbString += " where '$Where_IsAMember' is a member"
$request.UserKey = $Where_IsAMember
}
if ($PSBoundParameters.Keys -contains 'Filter') {
elseif ($PSBoundParameters.Keys -contains 'Filter') {
if ($Filter -eq '*') {
$Filter = ""
}
Expand All @@ -133,17 +128,19 @@
$request.Query = $Filter.Trim()
}
}
if ($PSBoundParameters.Keys -contains 'Domain') {
$verbString += " for domain '$Domain'"
$request.Domain = $Domain
}
elseif ( -not [String]::IsNullOrEmpty($Script:PSGSuite.CustomerID)) {
$verbString += " for customer '$($Script:PSGSuite.CustomerID)'"
$request.Customer = $Script:PSGSuite.CustomerID
}
else {
$verbString += " for customer 'my_customer'"
$request.Customer = "my_customer"
if ($PSBoundParameters.Keys -notcontains 'Where_IsAMember') {
if ($PSBoundParameters.Keys -contains 'Domain') {
$verbString += " for domain '$Domain'"
$request.Domain = $Domain
}
elseif ( -not [String]::IsNullOrEmpty($Script:PSGSuite.CustomerID)) {
$verbString += " for customer '$($Script:PSGSuite.CustomerID)'"
$request.Customer = $Script:PSGSuite.CustomerID
}
else {
$verbString += " for customer 'my_customer'"
$request.Customer = "my_customer"
}
}
if ($PageSize) {
$request.MaxResults = $PageSize
Expand Down
2 changes: 1 addition & 1 deletion PSGSuite/Public/Groups/Get-GSGroupMember.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function Get-GSGroupMember {
[String[]]
$Identity,
[parameter(Mandatory = $false,Position = 1,ParameterSetName = "Get")]
[Alias("PrimaryEmail","UserKey","Mail","User","UserEmail")]
[Alias("PrimaryEmail","UserKey","Mail","User","UserEmail","Members")]
[ValidateNotNullOrEmpty()]
[String[]]
$Member,
Expand Down
12 changes: 6 additions & 6 deletions PSGSuite/Public/Groups/Remove-GSGroupMember.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ function Remove-GSGroupMember {
<#
.SYNOPSIS
Removes members from a group
.DESCRIPTION
Removes members from a group
.PARAMETER Identity
The email or unique Id of the group to remove members from
.PARAMETER Member
The member or array of members to remove from the target group
.EXAMPLE
Remove-GSGroupMember -Identity admins -Member joe.smith,mark.taylor -Confirm:$false
Expand All @@ -25,7 +25,7 @@ function Remove-GSGroupMember {
[String]
$Identity,
[parameter(Mandatory = $true,ValueFromPipelineByPropertyName = $true,Position = 1)]
[Alias("PrimaryEmail","UserKey","Mail","User","UserEmail")]
[Alias("PrimaryEmail","UserKey","Mail","User","UserEmail","Members")]
[ValidateNotNullOrEmpty()]
[String[]]
$Member
Expand Down Expand Up @@ -63,4 +63,4 @@ function Remove-GSGroupMember {
}
}
}
}
}
59 changes: 59 additions & 0 deletions PSGSuite/Public/Groups/Test-GSGroupMembership.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
function Test-GSGroupMembership {
<#
.SYNOPSIS
Checks if a Group has a specific member
.DESCRIPTION
Checks if a Group has a specific member
.PARAMETER Identity
The email of the group
If only the email name-part is passed, the full email will be contstructed using the Domain from the active config
.PARAMETER Member
The user to confirm as a member of the Group
.EXAMPLE
Test-GSGroupMembership -Identity admins@domain.com -Member john@domain.com
Gets the group settings for admins@domain.com
#>
[OutputType('Google.Apis.Admin.Directory.directory_v1.Data.MembersHasMember')]
[cmdletbinding()]
Param
(
[parameter(Mandatory = $true,Position = 0,ValueFromPipeline = $true,ValueFromPipelineByPropertyName = $true)]
[Alias('GroupEmail','Group','Email')]
[String]
$Identity,
[parameter(Mandatory = $true,ValueFromPipelineByPropertyName = $true,Position = 1)]
[Alias("PrimaryEmail","UserKey","Mail","User","UserEmail","Members")]
[ValidateNotNullOrEmpty()]
[String]
$Member
)
Begin {
$serviceParams = @{
Scope = 'https://www.googleapis.com/auth/admin.directory.group'
ServiceType = 'Google.Apis.Admin.Directory.directory_v1.DirectoryService'
}
$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($_)
}
else {
Write-Error $_
}
}
}
}
2 changes: 1 addition & 1 deletion PSGSuite/Public/Groups/Update-GSGroupMember.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function Update-GSGroupMember {
[String]
$GroupEmail,
[parameter(Mandatory = $true,Position = 1,ValueFromPipelineByPropertyName = $true)]
[Alias("PrimaryEmail","UserKey","Mail","User","UserEmail","Email")]
[Alias("PrimaryEmail","UserKey","Mail","User","UserEmail","Email","Members")]
[ValidateNotNullOrEmpty()]
[String[]]
$Member,
Expand Down
9 changes: 1 addition & 8 deletions PSGSuite/Public/Users/Get-GSUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,7 @@ function Get-GSUser {
if ($MyInvocation.InvocationName -ne 'Get-GSUserList' -and $PSCmdlet.ParameterSetName -eq 'Get') {
foreach ($U in $User) {
try {
if ( -not ($U -as [decimal])) {
if ($U -ceq 'me') {
$U = $Script:PSGSuite.AdminEmail
}
elseif ($U -notlike "*@*.*") {
$U = "$($U)@$($Script:PSGSuite.Domain)"
}
}
Resolve-Email ([ref]$U)
Write-Verbose "Getting User '$U'"
$request = $service.Users.Get($U)
$request.Projection = $Projection
Expand Down
48 changes: 7 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,46 +143,12 @@ Update-GSSheetValue Export-GSSheet

[Full CHANGELOG here](https://github.com/scrthq/PSGSuite/blob/master/CHANGELOG.md)

#### 2.26.4
#### 2.27.0

* [Issue #177](https://github.com/scrthq/PSGSuite/issues/177) - _Thanks, [@WJurecki](https://github.com/WJurecki)!_
* Fixed: `Fields` parameter `Get-GSDriveFileList` would not set correctly with the default fields value, breaking the expected experience. Restored the same functionality

#### 2.26.3

* [Issue #182](https://github.com/scrthq/PSGSuite/issues/182) - _Thanks, [@aitcriver](https://github.com/aitcriver)!_
* Added: `FileOrganizer` role to `ValidateSet` for parameter `Role` on function `Add-GSDrivePermission`

#### 2.26.2

* [Issue #177](https://github.com/scrthq/PSGSuite/issues/177)
* Added: `Fields` parameter to `Get-GSDriveFileList`
* [Issue #178](https://github.com/scrthq/PSGSuite/issues/178)
* Fixed: `Start-GSDriveFileUpload` failing on PowerShell 4.0
* [Issue #179](https://github.com/scrthq/PSGSuite/issues/179)
* Added: `Ims` parameter to both `New-GSUser` and `Update-GSUser`
* Added: `Add-GSUserIm` function to create correct type for new `Ims` parameter.
* Miscellaneous
* Added: `Clear-PSGSuiteServiceCache` to clear the cache and dispose of any remaining open web clients.
* Improved overall service caching.
* Added: Support for `Cloud-Identity` licenses for `Get-GSUserLicense`
* Added: `OutputType` for all applicable Helper functions (i.e. `Add-GSUserIm`)

#### 2.26.1

* [Issue #172](https://github.com/scrthq/PSGSuite/issues/172)
* Fixed: `New-GoogleService` now using `New-Object` to prevent `[Google.Apis.Util.Store.FileDataStore]::new()` constructor issues in PowerShell 4.
* [Issue #173](https://github.com/scrthq/PSGSuite/issues/173)
* Added: `FolderColorRgb` parameter to `New-GSDriveFile` and `Update-GSDriveFile` to enable setting the color of a folder in Drive - _Thanks, [@WJurecki](https://github.com/WJurecki)!_
* [PR #174](https://github.com/scrthq/PSGSuite/pull/174) - _Thanks, [@WJurecki](https://github.com/WJurecki)!_
* Fixed: `Get-GSDriveFileList` filter concatenation so it joins multiple filters with ` and ` instead of just a space ` `.

#### 2.26.0

* [Issue #169](https://github.com/scrthq/PSGSuite/issues/169)
* Fixed: `Get-GSGmailMessage` fails to download attachments containing invalid characters (e.g. `:`)
* [Issue #168](https://github.com/scrthq/PSGSuite/issues/168)
* Added: `Add-GSUserLocation`
* Updated: `New-GSUser` and `Update-GSUser` to add in Location support
* [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).
* Miscellaneous
* Improved pipeline support for the `User` parameter across all pertinent functions, i.e. Drive, Calendar, Gmail, Sheets & Tasks APIs.
* 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.
Loading

0 comments on commit 3283bf2

Please sign in to comment.