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

Add Support for User Relation #130

Merged
merged 4 commits into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
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 @@ -194,7 +202,7 @@ function New-GSUser {
switch ($prop) {
PrimaryEmail {
if ($PSBoundParameters[$prop] -notlike "*@*.*") {
$PSBoundParameters[$prop] = "$($PSBoundParameters[$prop])@$($Script:PSGSuite.Domain)"
$PSBoundParameters[$prop] = "$($PSBoundParameters[$prop])@$($global:PSGSuite.Domain)"
}
$body.$prop = $PSBoundParameters[$prop]
}
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
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