diff --git a/PSGSuite.psd1 b/PSGSuite.psd1 index e75bf10f..b2f9713d 100644 --- a/PSGSuite.psd1 +++ b/PSGSuite.psd1 @@ -102,37 +102,7 @@ PowerShellVersion = '3.0' # NestedModules = @() # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. -FunctionsToExport = 'Add-GSDriveFilePermissions', 'Add-GSGmailDelegate', - 'Add-GSGmailFilter', 'Add-GSGroupMember', 'Clear-GSSheet', - 'Copy-GSDriveFile', 'Copy-GSSheet', 'Get-GSCalendarEventList', - 'Get-GSCalendarResourceList', 'Get-GSDataTransferApplicationList', - 'Get-GSDriveFile', 'Get-GSDriveFileInfo', 'Get-GSDriveFileList', - 'Get-GSDriveFilePermissionsList', 'Get-GSGmailDelegates', - 'Get-GSGmailFilterList', 'Get-GSGmailLabelList', - 'Get-GSGmailMessageInfo', 'Get-GSGmailMessageList', - 'Get-GSGmailSettings', 'Get-GSGroupList', 'Get-GSGroupMemberList', - 'Get-GSGroupSettings', 'Get-GSMobileDeviceList', 'Get-GSOrgUnitList', - 'Get-GSSheetInfo', 'Get-GSShortURLInfo', 'Get-GSShortURLList', - 'Get-GSToken', 'Get-GSUser', 'Get-GSUserASP', 'Get-GSUserASPList', - 'Get-GSUserLicenseInfo', 'Get-GSUserLicenseList', 'Get-GSUserList', - 'Get-GSUserPhoto', 'Get-GSUserSchemaInfo', 'Get-GSUserSchemaList', - 'Get-GSUserToken', 'Get-GSUserTokenList', - 'Get-GSUserVerificationCodes', 'Get-PSGSuiteConfig', 'Import-GSSheet', - 'New-GSCalendarEvent', 'New-GSCalendarResource', 'New-GSDriveFile', - 'New-GSGroup', 'New-GSOrganizationalUnit', 'New-GSSheet', - 'New-GSShortURL', 'New-GSUser', 'New-GSUserSchema', - 'New-GSUserVerificationCodes', 'Remove-GSGmailDelegate', - 'Remove-GSGmailFilter', 'Remove-GSGmailMessage', - 'Remove-GSGroupMember', 'Remove-GSMobileDevice', 'Remove-GSUser', - 'Remove-GSUserASP', 'Remove-GSUserLicense', 'Remove-GSUserSchema', - 'Remove-GSUserToken', 'Restore-GSUser', 'Revoke-GSToken', - 'Revoke-GSUserVerificationCodes', 'Send-GmailMessage', - 'Set-GSUserLicense', 'Set-PSGSuiteConfig', - 'Set-PSGSuiteDefaultDomain', 'Start-GSDataTransfer', - 'Switch-PSGSuiteDomain', 'Update-GSCalendarResource', - 'Update-GSDriveFile', 'Update-GSGroupSettings', - 'Update-GSOrganizationalUnit', 'Update-GSSheetValue', 'Update-GSUser', - 'Update-GSUserLicense', 'Update-GSUserSchema' +FunctionsToExport = '*' # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. CmdletsToExport = @() diff --git a/Public/Get-GSGroup.ps1 b/Public/Get-GSGroup.ps1 new file mode 100644 index 00000000..0a2c6953 --- /dev/null +++ b/Public/Get-GSGroup.ps1 @@ -0,0 +1,66 @@ +function Get-GSGroup { + [cmdletbinding()] + Param + ( + [parameter(Mandatory=$true,Position=0)] + [ValidateNotNullOrEmpty()] + [String] + $Group, + [parameter(Mandatory=$false)] + [String[]] + $Fields, + [parameter(Mandatory=$false)] + [String] + $AccessToken, + [parameter(Mandatory=$false)] + [ValidateNotNullOrEmpty()] + [String] + $P12KeyPath = $Script:PSGSuite.P12KeyPath, + [parameter(Mandatory=$false)] + [ValidateNotNullOrEmpty()] + [String] + $AppEmail = $Script:PSGSuite.AppEmail, + [parameter(Mandatory=$false)] + [ValidateNotNullOrEmpty()] + [String] + $AdminEmail = $Script:PSGSuite.AdminEmail + ) +if (!$AccessToken) + { + $AccessToken = Get-GSToken -P12KeyPath $P12KeyPath -Scopes "https://www.googleapis.com/auth/admin.directory.group" -AppEmail $AppEmail -AdminEmail $AdminEmail + } +$header = @{ + Authorization="Bearer $AccessToken" + } +$URI = "https://www.googleapis.com/admin/directory/v1/groups/$Group" +if ($Fields) + { + $URI = "$URI`?fields=" + $Fields | % {$URI = "$URI$_,"} + } +try + { + $response = Invoke-RestMethod -Method Get -Uri $URI -Headers $header | ForEach-Object {if($_.kind -like "*#*"){$_.PSObject.TypeNames.Insert(0,$(Convert-KindToType -Kind $_.kind));$_}else{$_}} + } +catch + { + try + { + $result = $_.Exception.Response.GetResponseStream() + $reader = New-Object System.IO.StreamReader($result) + $reader.BaseStream.Position = 0 + $reader.DiscardBufferedData() + $resp = $reader.ReadToEnd() + $response = $resp | ConvertFrom-Json | + Select-Object @{N="Error";E={$Error[0]}},@{N="Code";E={$_.error.Code}},@{N="Message";E={$_.error.Message}},@{N="Domain";E={$_.error.errors.domain}},@{N="Reason";E={$_.error.errors.reason}} + Write-Error "$(Get-HTTPStatus -Code $response.Code): $($response.Domain) / $($response.Message) / $($response.Reason)" + return + } + catch + { + Write-Error $resp + return + } + } +return $response +} \ No newline at end of file diff --git a/Public/Remove-GSGroup.ps1 b/Public/Remove-GSGroup.ps1 new file mode 100644 index 00000000..27d879f4 --- /dev/null +++ b/Public/Remove-GSGroup.ps1 @@ -0,0 +1,61 @@ +function Remove-GSGroup { + [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")] + Param + ( + [parameter(Mandatory=$true,Position=0)] + [String] + $Group, + [parameter(Mandatory=$false)] + [String] + $AccessToken, + [parameter(Mandatory=$false)] + [ValidateNotNullOrEmpty()] + [String] + $P12KeyPath = $Script:PSGSuite.P12KeyPath, + [parameter(Mandatory=$false)] + [ValidateNotNullOrEmpty()] + [String] + $AppEmail = $Script:PSGSuite.AppEmail, + [parameter(Mandatory=$false)] + [ValidateNotNullOrEmpty()] + [String] + $AdminEmail = $Script:PSGSuite.AdminEmail + ) +if (!$AccessToken) + { + $AccessToken = Get-GSToken -P12KeyPath $P12KeyPath -Scopes "https://www.googleapis.com/auth/admin.directory.group" -AppEmail $AppEmail -AdminEmail $AdminEmail + } +$header = @{ + Authorization="Bearer $AccessToken" + } +$URI = "https://www.googleapis.com/admin/directory/v1/groups/$Group" +if ($PSCmdlet.ShouldProcess($Group)) + { + try + { + $response = Invoke-RestMethod -Method Delete -Uri $URI -Headers $header -ContentType "application/json" + if (!$response){Write-Host "Group $Group successfully removed from the domain"} + } + catch + { + try + { + $result = $_.Exception.Response.GetResponseStream() + $reader = New-Object System.IO.StreamReader($result) + $reader.BaseStream.Position = 0 + $reader.DiscardBufferedData() + $resp = $reader.ReadToEnd() + $response = $resp | ConvertFrom-Json | + Select-Object @{N="Error";E={$Error[0]}},@{N="Code";E={$_.error.Code}},@{N="Message";E={$_.error.Message}},@{N="Domain";E={$_.error.errors.domain}},@{N="Reason";E={$_.error.errors.reason}} + Write-Error "$(Get-HTTPStatus -Code $response.Code): $($response.Domain) / $($response.Message) / $($response.Reason)" + return + } + catch + { + Write-Error $resp + return + } + } + } +return $response +} \ No newline at end of file