-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from mattwoolnough/master
Add Support for User Relation
- Loading branch information
Showing
3 changed files
with
122 additions
and
1 deletion.
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 |
---|---|---|
@@ -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 $_ | ||
} | ||
} | ||
} | ||
} |
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
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