Skip to content

Commit

Permalink
Merge pull request #130 from mattwoolnough/master
Browse files Browse the repository at this point in the history
Add Support for User Relation
  • Loading branch information
scrthq authored Dec 11, 2018
2 parents 6581fac + 26ded36 commit f31f5c9
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 1 deletion.
96 changes: 96 additions & 0 deletions PSGSuite/Public/Helpers/Add-GSUserRelation.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
function Add-GSUserRelation {
<#
.SYNOPSIS
Builds a Relation object to use when creating or updating a User
.DESCRIPTION
Builds a Relation object to use when creating or updating a User
.PARAMETER CustomType
If the external ID type is custom, this property holds the custom type
.PARAMETER Type
The type of the organization.
If using a CustomType
.PARAMETER Value
The value of the ID
.PARAMETER InputObject
Used for pipeline input of an existing UserExternalId object to strip the extra attributes and prevent errors
.EXAMPLE
$address = Add-GSUserAddress -Country USA -Locality Dallas -PostalCode 75000 Region TX -StreetAddress '123 South St' -Type Work -Primary
$phone = Add-GSUserPhone -Type Work -Value "(800) 873-0923" -Primary
$extId = Add-GSUserExternalId -Type Login_Id -Value jsmith2
$email = Add-GSUserEmail -Type work -Address [email protected]
New-GSUser -PrimaryEmail [email protected] -GivenName John -FamilyName Smith -Password (ConvertTo-SecureString -String 'Password123' -AsPlainText -Force) -ChangePasswordAtNextLogin -OrgUnitPath "/Users/New Hires" -IncludeInGlobalAddressList -Addresses $address -Phones $phone -ExternalIds $extId -Emails $email
Creates a user named John Smith and adds their work address, work phone, login_id and alternate non gsuite work email to the user object.
#>
[CmdletBinding(DefaultParameterSetName = "InputObject")]
Param
(
[Parameter(Mandatory = $false, ParameterSetName = "Fields")]
[String]
$CustomType,
[Parameter(Mandatory = $false, ParameterSetName = "Fields")]
[String]
$Type,
[Parameter(Mandatory = $false, ParameterSetName = "Fields")]
[String]
$Value,
[Parameter(Mandatory = $false, ParameterSetName = "Fields")]
[String]
$ETag,
[Parameter(Mandatory = $false, ValueFromPipeline = $true, ParameterSetName = "InputObject")]
[Google.Apis.Admin.Directory.directory_v1.Data.UserRelation[]]
$InputObject
)
Begin {
$propsToWatch = @(
'CustomType'
'Type',
'Value'
'ETag'
)
if ($PSBoundParameters.Keys -contains 'CustomType') {
$PSBoundParameters['Type'] = 'CUSTOM'
}
}
Process {
try {
switch ($PSCmdlet.ParameterSetName) {
Fields {
$obj = New-Object 'Google.Apis.Admin.Directory.directory_v1.Data.UserRelation'
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.Admin.Directory.directory_v1.Data.UserRelation'
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 $_
}
}
}
}
17 changes: 16 additions & 1 deletion PSGSuite/Public/Users/New-GSUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ function New-GSUser {
This parameter expects a 'Google.Apis.Admin.Directory.directory_v1.Data.UserOrganization[]' object type. You can create objects of this type easily by using the function 'Add-GSUserOrganization'
.PARAMETER Relations
The relation objects of the user
This parameter expects a 'Google.Apis.Admin.Directory.directory_v1.Data.UserRelation[]' object type. You can create objects of this type easily by using the function 'Add-GSUserRelation'
.PARAMETER Phones
The phone objects of the user
Expand Down Expand Up @@ -143,6 +148,9 @@ function New-GSUser {
[Google.Apis.Admin.Directory.directory_v1.Data.UserOrganization[]]
$Organizations,
[parameter(Mandatory = $false)]
[Google.Apis.Admin.Directory.directory_v1.Data.UserRelation[]]
$Relations,
[parameter(Mandatory = $false)]
[Google.Apis.Admin.Directory.directory_v1.Data.UserPhone[]]
$Phones,
[parameter(Mandatory = $false)]
Expand Down Expand Up @@ -222,6 +230,13 @@ function New-GSUser {
}
$body.Organizations = $orgList
}
Relations {
$relList = New-Object 'System.Collections.Generic.List`1[Google.Apis.Admin.Directory.directory_v1.Data.UserRelation]'
foreach ($relation in $Relations) {
$relList.Add($relation)
}
$body.Relations = $relList
}
Phones {
$phoneList = New-Object 'System.Collections.Generic.List`1[Google.Apis.Admin.Directory.directory_v1.Data.UserPhone]'
foreach ($phone in $Phones) {
Expand Down Expand Up @@ -258,4 +273,4 @@ function New-GSUser {
}
}
}
}
}
10 changes: 10 additions & 0 deletions PSGSuite/Public/Users/Update-GSUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ function Update-GSUser {
[Google.Apis.Admin.Directory.directory_v1.Data.UserOrganization[]]
$Organizations,
[parameter(Mandatory = $false)]
[Google.Apis.Admin.Directory.directory_v1.Data.UserRelation[]]
$Relations,
[parameter(Mandatory = $false)]
[Google.Apis.Admin.Directory.directory_v1.Data.UserPhone[]]
$Phones,
[parameter(Mandatory = $false)]
Expand Down Expand Up @@ -251,6 +254,13 @@ function Update-GSUser {
}
$body.Organizations = $orgList
}
Relations {
$relList = New-Object 'System.Collections.Generic.List`1[Google.Apis.Admin.Directory.directory_v1.Data.UserRelation]'
foreach ($relation in $Relations) {
$relList.Add($relation)
}
$body.Relations = $relList
}
Phones {
$phoneList = New-Object 'System.Collections.Generic.List`1[Google.Apis.Admin.Directory.directory_v1.Data.UserPhone]'
foreach ($phone in $Phones) {
Expand Down

0 comments on commit f31f5c9

Please sign in to comment.