-
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.
!deploy v2.22.4 with ChromeOSDevice support to resolve #147
## 2.22.4 * [Issue #147](#147) * Added: `Get-GSChromeOSDevice` - Handles Get or List requests, depending on if you specify a ResourceId or not. * Added: `Update-GSChromeOSDevice` - Handles Action, Move and/or Patch requests depending on the parameters passed.
- Loading branch information
Showing
8 changed files
with
406 additions
and
19 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
function Move-GSChromeOSDevice { | ||
<# | ||
.SYNOPSIS | ||
Moves a ChromeOS device to a new OrgUnit | ||
.DESCRIPTION | ||
Moves a ChromeOS device to a new OrgUnit | ||
.PARAMETER ResourceId | ||
The unique ID of the device you would like to move. | ||
.PARAMETER OrgUnitPath | ||
Full path of the target organizational unit or its ID | ||
.EXAMPLE | ||
Move-GSChromeOSDevice -ResourceId 'AFiQxQ8Qgd-rouSmcd2UnuvhYV__WXdacTgJhPEA1QoQJrK1hYbKJXm-8JFlhZOjBF4aVbhleS2FVQk5lI069K2GULpteTlLVpKLJFSLSL' -OrgUnitPath '/Corp' | ||
Moves the ChromeOS device specified to the /Corp OrgUnit | ||
#> | ||
[OutputType('Google.Apis.Admin.Directory.directory_v1.Data.ChromeOSDevice')] | ||
[cmdletbinding()] | ||
Param | ||
( | ||
[parameter(Mandatory = $true,Position = 0,ValueFromPipelineByPropertyName = $true)] | ||
[Alias('Id','Device','DeviceId')] | ||
[String[]] | ||
$ResourceId, | ||
[parameter(Mandatory = $true,Position = 1)] | ||
[String] | ||
$OrgUnitPath | ||
) | ||
Begin { | ||
$serviceParams = @{ | ||
Scope = 'https://www.googleapis.com/auth/admin.directory.device.chromeos' | ||
ServiceType = 'Google.Apis.Admin.Directory.directory_v1.DirectoryService' | ||
} | ||
$service = New-GoogleService @serviceParams -Verbose:$false | ||
$customerId = if ($Script:PSGSuite.CustomerID) { | ||
$Script:PSGSuite.CustomerID | ||
} | ||
else { | ||
"my_customer" | ||
} | ||
$toMove = New-Object 'System.Collections.Generic.List[string]' | ||
} | ||
Process { | ||
$ResourceId | ForEach-Object { | ||
$toMove.Add($_) | ||
} | ||
} | ||
End { | ||
try { | ||
Write-Verbose "Moving the following Chrome OS Devices to OrgUnitPath '$OrgUnitPath':`n - $($toMove -join "`n - ")" | ||
$body = New-Object 'Google.Apis.Admin.Directory.directory_v1.Data.ChromeOsMoveDevicesToOu' -Property @{ | ||
DeviceIds = $toMove | ||
} | ||
$request = $service.Chromeosdevices.MoveDevicesToOu($body,$customerId,$OrgUnitPath) | ||
$request.Execute() | ||
Write-Verbose "The Chrome OS devices were successfully moved." | ||
} | ||
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,166 @@ | ||
function Get-GSChromeOSDevice { | ||
<# | ||
.SYNOPSIS | ||
Gets the list of Chrome OS Devices registered for the user's account | ||
.DESCRIPTION | ||
Gets the list of Chrome OS Devices registered for the user's account | ||
.PARAMETER ResourceId | ||
Immutable ID of Chrome OS Device. Gets the list of Chrome OS devices if excluded. | ||
.PARAMETER OrgUnitPath | ||
The full path of the organizational unit or its unique ID. | ||
.PARAMETER Filter | ||
Search string in the format given at: http://support.google.com/chromeos/a/bin/answer.py?answer=1698333 | ||
.PARAMETER Projection | ||
Restrict information returned to a set of selected fields. | ||
Acceptable values are: | ||
* "BASIC": Includes only the basic metadata fields (e.g., deviceId, model, status, type, and status) | ||
* "FULL": Includes all metadata fields | ||
Defauls to "FULL" | ||
.PARAMETER PageSize | ||
Page size of the result set | ||
.PARAMETER OrderBy | ||
Device property to use for sorting results. | ||
Acceptable values are: | ||
* "annotatedLocation": Chrome device location as annotated by the administrator. | ||
* "annotatedUser": Chrome device user as annotated by the administrator. | ||
* "lastSync": The date and time the Chrome device was last synchronized with the policy settings in the Admin console. | ||
* "notes": Chrome device notes as annotated by the administrator. | ||
* "serialNumber": The Chrome device serial number entered when the device was enabled. | ||
* "status": Chrome device status. For more information, see the chromeosdevices resource. | ||
* "supportEndDate": Chrome device support end date. This is applicable only for devices purchased directly from Google. | ||
.PARAMETER SortOrder | ||
Whether to return results in ascending or descending order. Must be used with the OrderBy parameter. | ||
Acceptable values are: | ||
* "ASCENDING": Ascending order. | ||
* "DESCENDING": Descending order. | ||
.EXAMPLE | ||
Get-GSChromeOSDevice | ||
Gets the Chrome OS Device list for the customer | ||
#> | ||
[OutputType('Google.Apis.Admin.Directory.directory_v1.Data.ChromeOSDevice')] | ||
[cmdletbinding(DefaultParameterSetName = "List")] | ||
Param | ||
( | ||
[parameter(Mandatory = $false,Position = 0,ValueFromPipeline = $true,ValueFromPipelineByPropertyName = $true,ParameterSetName = "Get")] | ||
[Alias('Id','Device','DeviceId')] | ||
[String[]] | ||
$ResourceId, | ||
[parameter(Mandatory = $false,ParameterSetName = "List")] | ||
[Alias('Query')] | ||
[String] | ||
$Filter, | ||
[parameter(Mandatory = $false,ParameterSetName = "List")] | ||
[String] | ||
$OrgUnitPath, | ||
[parameter(Mandatory = $false)] | ||
[ValidateSet("BASIC","FULL")] | ||
[String] | ||
$Projection = "FULL", | ||
[parameter(Mandatory = $false,ParameterSetName = "List")] | ||
[ValidateRange(1,100)] | ||
[Alias('MaxResults')] | ||
[Int] | ||
$PageSize = "100", | ||
[parameter(Mandatory = $false,ParameterSetName = "List")] | ||
[ValidateSet("annotatedLocation","annotatedUser","lastSync","notes","serialNumber","status","supportEndDate")] | ||
[String] | ||
$OrderBy, | ||
[parameter(Mandatory = $false,ParameterSetName = "List")] | ||
[ValidateSet("ASCENDING","DESCENDING")] | ||
[String] | ||
$SortOrder | ||
) | ||
Begin { | ||
$serviceParams = @{ | ||
Scope = 'https://www.googleapis.com/auth/admin.directory.device.chromeos' | ||
ServiceType = 'Google.Apis.Admin.Directory.directory_v1.DirectoryService' | ||
} | ||
$service = New-GoogleService @serviceParams | ||
$customerId = if ($Script:PSGSuite.CustomerID) { | ||
$Script:PSGSuite.CustomerID | ||
} | ||
else { | ||
"my_customer" | ||
} | ||
|
||
} | ||
Process { | ||
try { | ||
switch ($PSCmdlet.ParameterSetName) { | ||
Get { | ||
foreach ($dev in $ResourceId) { | ||
try { | ||
Write-Verbose "Getting Chrome OS Device '$dev'" | ||
$request = $service.Chromeosdevices.Get($customerId,$dev) | ||
$request.Execute() | ||
} | ||
catch { | ||
if ($ErrorActionPreference -eq 'Stop') { | ||
$PSCmdlet.ThrowTerminatingError($_) | ||
} | ||
else { | ||
Write-Error $_ | ||
} | ||
} | ||
} | ||
} | ||
List { | ||
$request = $service.Chromeosdevices.List($customerId) | ||
if ($PSBoundParameters.Keys -contains 'Filter') { | ||
Write-Verbose "Getting Chrome OS Device list for filter '$Filter'" | ||
$request.Query = $PSBoundParameters['Filter'] | ||
} | ||
else { | ||
Write-Verbose "Getting Chrome OS Device list" | ||
} | ||
foreach ($key in $PSBoundParameters.Keys | Where-Object {$_ -ne 'Filter'}) { | ||
switch ($key) { | ||
PageSize { | ||
$request.MaxResults = $PSBoundParameters[$key] | ||
} | ||
default { | ||
if ($request.PSObject.Properties.Name -contains $key) { | ||
$request.$key = $PSBoundParameters[$key] | ||
} | ||
} | ||
} | ||
} | ||
[int]$i = 1 | ||
do { | ||
$result = $request.Execute() | ||
$result.Chromeosdevices | ||
if ($result.NextPageToken) { | ||
$request.PageToken = $result.NextPageToken | ||
} | ||
[int]$retrieved = ($i + $result.Chromeosdevices.Count) - 1 | ||
Write-Verbose "Retrieved $retrieved Chrome OS Devices..." | ||
[int]$i = $i + $result.Chromeosdevices.Count | ||
} | ||
until (!$result.NextPageToken) | ||
} | ||
} | ||
} | ||
catch { | ||
if ($ErrorActionPreference -eq 'Stop') { | ||
$PSCmdlet.ThrowTerminatingError($_) | ||
} | ||
else { | ||
Write-Error $_ | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.