Cannot update email address of group
dresken opened this issue · 2 comments
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:
- Update-GSGroupSettings -Identity $groupId -Email new_email@example.com
- 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
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'`
Closed via #353