diff --git a/PSGSuite/Public/Helpers/Add-GSUserRelation.ps1 b/PSGSuite/Public/Helpers/Add-GSUserRelation.ps1 new file mode 100644 index 00000000..7d8d95da --- /dev/null +++ b/PSGSuite/Public/Helpers/Add-GSUserRelation.ps1 @@ -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 jsmith@contoso.com + + New-GSUser -PrimaryEmail john.smith@domain.com -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 $_ + } + } + } +} diff --git a/PSGSuite/Public/Users/New-GSUser.ps1 b/PSGSuite/Public/Users/New-GSUser.ps1 index e45745b4..d54a8464 100644 --- a/PSGSuite/Public/Users/New-GSUser.ps1 +++ b/PSGSuite/Public/Users/New-GSUser.ps1 @@ -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 @@ -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)] @@ -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) { @@ -258,4 +273,4 @@ function New-GSUser { } } } -} \ No newline at end of file +} diff --git a/PSGSuite/Public/Users/Update-GSUser.ps1 b/PSGSuite/Public/Users/Update-GSUser.ps1 index 63064e4a..c0d74424 100644 --- a/PSGSuite/Public/Users/Update-GSUser.ps1 +++ b/PSGSuite/Public/Users/Update-GSUser.ps1 @@ -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)] @@ -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) {