-
Notifications
You must be signed in to change notification settings - Fork 67
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
comparecloud
wants to merge
2
commits into
SCRT-HQ:main
Choose a base branch
from
comparecloud:master
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Master #327
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
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 $_ | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 $_ | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 $_ | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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