Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot update email address of group #344

Closed
dresken opened this issue Feb 9, 2021 · 2 comments
Closed

Cannot update email address of group #344

dresken opened this issue Feb 9, 2021 · 2 comments
Milestone

Comments

@dresken
Copy link

dresken commented Feb 9, 2021

Describe the bug
Cannot update email address of group. Looks like unreleased version may include updated Set-GSGroupSettings (but there's not an updated Update-GSGroupSettings) - however this drops the -Email parameter entirely. I haven't been able to locate a replacement for this functionality in PSGSuite. The API doco with https://developers.google.com/admin-sdk/groups-settings/v1/reference/groups say Email gets changed with Directory API (which I'm guessing means there should be a Update-GSGroup)

To Reproduce
Steps to reproduce the behavior:

  1. Update-GSGroupSettings -Identity $groupId -Email new_email@example.com
  2. Returns error
    Update-GSGroupSettings : Exception calling "Execute" with "0" argument(s): "Google.Apis.Requests.RequestError
    Invalid Value [400]
    Errors [
    Message[Invalid Value] Location[ - ] Reason[invalid] Domain[global]
    ]

Expected behavior
Group Email address is updated to the new value

Environment (please complete the following information):

  • OS: Windows 2019
  • PowerShell Version: 5.1
  • PSGSuite Version: 2.36.4
@Buenno
Copy link

Buenno commented Jun 5, 2021

I don't really have the time to write this to spec or generate a PR, and it's a bit...hacky, but this works for updating the group email address. Add the function to the psd1 file and then add the new function name to the module manifest function export list (psd1). Reimport the module once complete and you should be good to go.

I really should have used a parameter set for the -NewEmail parameter as Powershell is throw an error if you use the new function and don't specify that parameter. I'll try and sort this next week and generate a PR.

`function Update-GSGroup {
<#
.SYNOPSIS
Updates a new Google Group

.DESCRIPTION
Updates a new Google Group

.PARAMETER Email
Current email address of group

.PARAMETER NewEmail
The updated email address of group

.PARAMETER Name
The updated name of the group

.PARAMETER Description
The updated description of the group

.EXAMPLE
Update-GSGroup -Email appdev -Name "Application Developers" -Description "App Dev team members" -NewEmail appdevelopers

Updates a group named "Application Developers" with the email "appdevelopers@domain.com" and description "App Dev team members"
#>
[OutputType('Google.Apis.Admin.Directory.directory_v1.Data.Group')]
[cmdletbinding()]
Param
(
    [parameter(Mandatory = $true)]
    [String]
    $Email,
    [parameter(Mandatory = $false)]
    [String]
    $Name,
    [parameter(Mandatory = $false)]
    [String]
    $Description,
    [parameter(Mandatory = $false)]
    [String]
    $NewEmail
)
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]$Email)
        Write-Verbose "Updating group '$Email'"
        $body = New-Object 'Google.Apis.Admin.Directory.directory_v1.Data.Group'
        foreach ($prop in $PSBoundParameters.Keys | Where-Object {$body.PSObject.Properties.Name -contains $_}) {
            switch ($prop) {
                Email {
                    $body.Email = $NewEmail
                }
                Default {
                    $body.$prop = $PSBoundParameters[$prop]
                }
            }
        }
        $request = $service.Groups.Patch($body, $Email)
        $request.Alt = "Json"
        $request.Execute()
    }
    catch {
        if ($ErrorActionPreference -eq 'Stop') {
            $PSCmdlet.ThrowTerminatingError($_)
        }
        else {
            Write-Error $_
        }
    }
}

}

Export-ModuleMember -Function 'Update-GSGroup'`

@Buenno Buenno mentioned this issue Jun 6, 2021
@FISHMANPET FISHMANPET added this to the v2.37.0 milestone Apr 1, 2022
@FISHMANPET
Copy link
Collaborator

Closed via #353

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants