Skip to content

Commit

Permalink
+++
Browse files Browse the repository at this point in the history
  • Loading branch information
scrthq committed Feb 20, 2017
1 parent cb950f0 commit bf92f8b
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 31 deletions.
32 changes: 1 addition & 31 deletions PSGSuite.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @()
Expand Down
66 changes: 66 additions & 0 deletions Public/Get-GSGroup.ps1
Original file line number Diff line number Diff line change
@@ -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
}
61 changes: 61 additions & 0 deletions Public/Remove-GSGroup.ps1
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit bf92f8b

Please sign in to comment.