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

Master #327

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions PSGSuite/Public/Contacts/Get-GSContactList.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Function Get-GSContactList {
.EXAMPLE
Get-GSContactList -User [email protected]

.NOTES
Updated: 6 Oct 2020 by Chris O'Sullivan / CompareCloud
Updates: Added Organization details to output object
#>
[cmdletbinding()]
Param
Expand Down Expand Up @@ -60,6 +63,9 @@ Function Get-GSContactList {
FamilyName = $i.name.familyName
EmailAddresses = $(if($i.email.address){$i.email.address}else{$null})
PhoneNumber = $i.phonenumber
JobTitle = $i.organization.orgTitle #added by CompareCloud 6 Oct 2020
Department = $i.organization.orgDepartment #added by CompareCloud 6 Oct 2020
CompanyName = $i.organization.orgName #added by CompareCloud 6 Oct 2020
Updated = $i.updated
Edited = $i.edited.'#text'
Path = $(if($i.email.rel){$i.email.rel}else{$null})
Expand Down
109 changes: 109 additions & 0 deletions PSGSuite/Public/Contacts/New-GSContact.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
function New-GSContact {
<#
.SYNOPSIS
Creates a new G Suite Contact

.DESCRIPTION
Creates a new G Suite Contact

.PARAMETER GivenName
The given (first) name of the Contact

.PARAMETER FamilyName
The family (last) name of the Contact

.PARAMETER Emails
The email objects of the Contact

This parameter expects a 'Google.Apis.PeopleService.v1.Data.EmailAddress[]' object type. You can create objects of this type easily by using the function 'Add-GSContactEmail'

.PARAMETER Organizations
The organization objects of the Contact

This parameter expects a 'Google.Apis.PeopleService.v1.Data.Organization[]' object type. You can create objects of this type easily by using the function 'Add-GSContactOrganization'

.EXAMPLE
$emails = Add-GSContactEmail -Type work -Address [email protected] -DisplayName "John Smith | Google"
$organizations = Add-GSContactOrganization -Title "Sales Manager" -Department "Sales" -Name "Google"

New-GSContact -GivenName John -FamilyName Smith -Emails $email -Organizations $organizations

Creates a contact named John Smith and adds their work address, work phone, login_id and alternate non gsuite work email to the Contact object.

.NOTES
Author: Chris O'Sullivan / CompareCloud
Acknowledgements: Used existing New-GSUser function scructure and format to maintain convention
Date: 6 Oct 2020
Version: 1.0
#>
[OutputType('Google.Apis.PeopleService.v1.Data.Person')]
[cmdletbinding()]
Param
(
[parameter(Mandatory = $true)]
[String]
$GivenName,
[parameter(Mandatory = $true)]
[String]
$FamilyName,
[parameter(Mandatory = $false)]
[Google.Apis.PeopleService.v1.Data.EmailAddress[]]
$EmailAddresses,
[parameter(Mandatory = $false)]
[Google.Apis.PeopleService.v1.Data.Organization[]]
$Organizations
)
Begin {
$serviceParams = @{
Scope = 'https://www.googleapis.com/auth/contacts'
ServiceType = 'Google.Apis.PeopleService.v1.PeopleServiceService'
}
$service = New-GoogleService @serviceParams
}
Process {
try {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is $PrimaryEmail a remnant when testing? Not seeing it on the parameter list

Write-Verbose "Creating contact '$PrimaryEmail'"
$body = New-Object 'Google.Apis.PeopleService.v1.Data.Person'
$name = New-Object 'Google.Apis.PeopleService.v1.Data.Name' -Property @{
GivenName = $GivenName
FamilyName = $FamilyName
}
$nameList = New-Object 'System.Collections.Generic.List`1[Google.Apis.PeopleService.v1.Data.Name]'
$nameList.Add($name)

$body.Names = $nameList
foreach ($prop in $PSBoundParameters.Keys | Where-Object {$body.PSObject.Properties.Name -contains $_}) {
switch ($prop) {
EmailAddresses {
$emailList = New-Object 'System.Collections.Generic.List`1[Google.Apis.PeopleService.v1.Data.EmailAddress]'
foreach ($email in $EmailAddresses) {
$emailList.Add($email)
}
$body.EmailAddresses = $emailList
}
Organizations {
$orgList = New-Object 'System.Collections.Generic.List`1[Google.Apis.PeopleService.v1.Data.Organization]'
foreach ($organization in $Organizations) {
$orgList.Add($organization)
}
$body.Organizations = $orgList
}
Default {
$body.$prop = $PSBoundParameters[$prop]
}
}
}
$request = $service.People.CreateContact($body)
$request.Execute()
}
catch {
if ($ErrorActionPreference -eq 'Stop') {
$PSCmdlet.ThrowTerminatingError($_)
}
else {
Write-Error $_
}
}
}
}

97 changes: 97 additions & 0 deletions PSGSuite/Public/Helpers/Add-GSContactEmail.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
function Add-GSContactEmail {
<#
.SYNOPSIS
Builds a Email object to use when creating or updating a contact

.DESCRIPTION
Builds a Email object to use when creating or updating a contact

.PARAMETER Address
The contact's email address. Also serves as the email ID. This value can be the contact's primary email address or an alias.

.PARAMETER Type
The type of the email account.

Acceptable values are:
* "home"
* "other"
* "work"

.PARAMETER InputObject
Used for pipeline input of an existing Email object to strip the extra attributes and prevent errors

.EXAMPLE
$emails = Add-GSContactEmail -Type work -Address [email protected] -DisplayName "John Smith | Google"
$organizations = Add-GSContactOrganization -Title "Sales Manager" -Department "Sales" -Name "Google"

New-GSContact -GivenName John -FamilyName Smith -Emails $email -Organizations $organizations

Creates a contact named John Smith and adds their work address, work phone, login_id and alternate non gsuite work email to the Contact object.

.NOTES
Author: Chris O'Sullivan / CompareCloud
Acknowledgements: Used existing Add-GSUserEmail function scructure and format to maintain convention
Date: 6 Oct 2020
Version: 1.0
#>
[OutputType('Google.Apis.PeopleService.v1.Data.EmailAddress')]
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $false, ParameterSetName = "Fields")]
[String]
$DisplayName,
[Parameter(Mandatory = $false, ParameterSetName = "Fields")]
[String]
$Value,
[Parameter(Mandatory = $false, ParameterSetName = "Fields")]
[ValidateSet('home', 'other', 'work')]
[String]
$Type,
[Parameter(Mandatory = $false, ValueFromPipeline = $true, ParameterSetName = "InputObject")]
[Google.Apis.PeopleService.v1.Data.EmailAddress[]]
$InputObject
)
Begin {
$propsToWatch = @(
'DisplayName'
'Value'
'Type'
)
}
Process {
try {
switch ($PSCmdlet.ParameterSetName) {
Fields {
$obj = New-Object 'Google.Apis.PeopleService.v1.Data.EmailAddress'
foreach ($prop in $PSBoundParameters.Keys | Where-Object {$obj.PSObject.Properties.Name -contains $_}) {
if ($prop -eq 'Type') {
$obj.$prop = $PSBoundParameters[$prop].ToLower()
}
else {
$obj.$prop = $PSBoundParameters[$prop]
}
}
$obj
}
InputObject {
foreach ($iObj in $InputObject) {
$obj = New-Object 'Google.Apis.PeopleService.v1.Data.EmailAddress'
foreach ($prop in $iObj.PSObject.Properties.Name | Where-Object {$obj.PSObject.Properties.Name -contains $_ -and $propsToWatch -contains $_}) {
$obj.$prop = $iObj.$prop
}
$obj
}
}
}
}
catch {
if ($ErrorActionPreference -eq 'Stop') {
$PSCmdlet.ThrowTerminatingError($_)
}
else {
Write-Error $_
}
}
}
}
89 changes: 89 additions & 0 deletions PSGSuite/Public/Helpers/Add-GSContactOrganization.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
function Add-GSContactOrganization {
<#
.SYNOPSIS
Builds a Organization object to use when creating or updating a Contact

.DESCRIPTION
Builds a Organization object to use when creating or updating a Contact

.PARAMETER Department
Department within the organization

.PARAMETER Name
Name of the organization

.PARAMETER Title
Title (designation) of the user in the organization

.PARAMETER InputObject
Used for pipeline input of an existing UserExternalId object to strip the extra attributes and prevent errors

.EXAMPLE
$emails = Add-GSContactEmail -Type work -Address [email protected] -DisplayName "John Smith | Google"
$organizations = Add-GSContactOrganization -Title "Sales Manager" -Department "Sales" -Name "Google"

New-GSContact -GivenName John -FamilyName Smith -Emails $email -Organizations $organizations

Creates a contact named John Smith and adds their work address, work phone, login_id and alternate non gsuite work email to the Contact object.

.NOTES
Author: Chris O'Sullivan / CompareCloud
Acknowledgements: Used existing Add-GSUserOrganization function scructure and format to maintain convention
Date: 6 Oct 2020
Version: 1.0
#>
[OutputType('Google.Apis.PeopleService.v1.Data.Organization')]
[CmdletBinding(DefaultParameterSetName = "InputObject")]
Param
(
[Parameter(Mandatory = $false, ParameterSetName = "Fields")]
[String]
$Department,
[Parameter(Mandatory = $false, ParameterSetName = "Fields")]
[String]
$Name,
[Parameter(Mandatory = $false, ParameterSetName = "Fields")]
[String]
$Title,
[Parameter(Mandatory = $false, ValueFromPipeline = $true, ParameterSetName = "InputObject")]
[Google.Apis.PeopleService.v1.Data.Organization[]]
$InputObject
)
Begin {
$propsToWatch = @(
'Department'
'Name'
'Title'
)
}
Process {
try {
switch ($PSCmdlet.ParameterSetName) {
Fields {
$obj = New-Object 'Google.Apis.PeopleService.v1.Data.Organization'
foreach ($prop in $PSBoundParameters.Keys | Where-Object {$obj.PSObject.Properties.Name -contains $_}) {
$obj.$prop = $PSBoundParameters[$prop]
}
$obj
}
InputObject {
foreach ($iObj in $InputObject) {
$obj = New-Object 'Google.Apis.PeopleService.v1.Data.Organization'
foreach ($prop in $iObj.PSObject.Properties.Name | Where-Object {$obj.PSObject.Properties.Name -contains $_ -and $propsToWatch -contains $_}) {
$obj.$prop = $iObj.$prop
}
$obj
}
}
}
}
catch {
if ($ErrorActionPreference -eq 'Stop') {
$PSCmdlet.ThrowTerminatingError($_)
}
else {
Write-Error $_
}
}
}
}