-
Notifications
You must be signed in to change notification settings - Fork 67
Added Get-GSChromeDeviceTelemetry #365
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
Open
Foggy2
wants to merge
2
commits into
SCRT-HQ:main
Choose a base branch
from
Foggy2:Get-GSChromeDeviceTelemetry
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,137 @@ | ||
| Function Get-GSChromeDeviceTelemetry { | ||
| <# | ||
| .SYNOPSIS | ||
| Gets a list of telemetry records for managed Chrome devices. | ||
| .DESCRIPTION | ||
| Gets a list of telemetry records for managed Chrome devices. | ||
| .PARAMETER FieldMask | ||
| The fields to retrieve for each Chrome device. Acceptable values are: | ||
| * "name" | ||
| * "customer" | ||
| * "orgUnitId" | ||
| * "deviceId" | ||
| * "serialNumber" | ||
| * "cpuInfo" | ||
| * "cpuStatusReport" | ||
| * "memoryInfo" | ||
| * "memoryStatusReport" | ||
| * "networkStatusReport" | ||
| * "osUpdateStatus" | ||
| * "graphicsInfo" | ||
| * "graphicsStatusReport" | ||
| * "batteryInfo" | ||
| * "batteryStatusReport" | ||
| * "storageInfo" | ||
| * "storageStatusReport" | ||
| The default value is to return all fields. | ||
| .PARAMETER Filter | ||
| Query string for searching Chrome device fields. Supported filter fields are: | ||
| * "orgUnitId" | ||
| * "serialNumber" | ||
| For more information on constructing filter queries, see: https://developers.google.com/admin-sdk/directory/v1/guides/search-users | ||
| PowerShell filter syntax here is supported as "best effort". Please use Google's filter operators and syntax to ensure best results | ||
| .PARAMETER PageSize | ||
| Page size of the result set | ||
| .PARAMETER Limit | ||
| The maximum amount of results you want returned. Exclude or set to 0 to return all results | ||
| .EXAMPLE | ||
| Get-GSChromeDeviceTelemetry | ||
| Gets the list of all Chrome devices including all telemetry fields | ||
| .EXAMPLE | ||
| Get-GSChromeDeviceTelemetry -Filter "orgUnitId -eq ABCDEFG" | ||
| Gets the list of all Chrome devices found in the ABCDEFG OU and includes all telemetry fields | ||
| .EXAMPLE | ||
| Get-GSChromeDeviceTelemetry -FieldMask deviceId, batteryInfo, cpuInfo | ||
| Gets the list of all Chrome devices including only the deviceId, batteryInfo and cpuInfo telemetry fields. | ||
| .LINK | ||
| https://developers.google.com/chrome/management/reference/rest/v1/customers.telemetry.devices | ||
| #> | ||
| [OutputType('Google.Apis.ChromeManagement.v1.Data.GoogleChromeManagementV1TelemetryDevice')] | ||
| Param | ||
| ( | ||
| [parameter(Mandatory = $false)] | ||
| [Alias("Query")] | ||
| [string] | ||
| $Filter, | ||
| [parameter(Mandatory = $false)] | ||
| [ALias("Fields")] | ||
| [ValidateSet("name", "customer", "orgUnitId", "deviceId", "serialNumber", "cpuInfo", "cpuStatusReport", "memoryInfo", "memoryStatusReport", "networkStatusReport", "osUpdateStatus", "graphicsInfo", "graphicsStatusReport", "batteryInfo", "batteryStatusReport", "storageInfo", "storageStatusReport")] | ||
| [String[]] | ||
| $FieldMask = @("name", "customer", "orgUnitId", "deviceId", "serialNumber", "cpuInfo", "cpuStatusReport", "memoryInfo", "memoryStatusReport", "networkStatusReport", "osUpdateStatus", "graphicsInfo", "graphicsStatusReport", "batteryInfo", "batteryStatusReport", "storageInfo", "storageStatusReport"), | ||
| [parameter(Mandatory = $false)] | ||
| [ValidateRange(1,200)] | ||
| [Alias("MaxResults")] | ||
| [Int] | ||
| $PageSize = 200, | ||
| [parameter(Mandatory = $false)] | ||
| [Alias('First')] | ||
| [Int] | ||
| $Limit = 0 | ||
| ) | ||
| Begin { | ||
| $serviceParams = @{ | ||
| Scope = 'https://www.googleapis.com/auth/chrome.management.telemetry.readonly' | ||
| ServiceType = 'Google.Apis.ChromeManagement.v1.ChromeManagementService' | ||
| } | ||
| $service = New-GoogleService @serviceParams | ||
| } | ||
| Process { | ||
| $verbString = "Getting all Chrome device telemetry records" | ||
| try { | ||
| $request = $service.Customers.Telemetry.Devices.List('customers/my_customer') | ||
| $ReadMask = $FieldMask -join "," | ||
| $verbString += " for fields '$ReadMask'" | ||
| $Request.ReadMask = $ReadMask | ||
| if ($PSBoundParameters.Keys -contains 'Filter') { | ||
| if ($Filter -eq '*') { | ||
| $Filter = "" | ||
| } | ||
| else { | ||
| $Filter = "$($Filter -join " ")" | ||
| } | ||
| $Filter = $Filter -replace " -eq ","=" -replace " -like ",":" -replace " -match ",":" -replace " -contains ",":" -creplace "'True'","True" -creplace "'False'","False" | ||
| if (-not [String]::IsNullOrEmpty($Filter.Trim())) { | ||
| $verbString += " matching query '$($Filter.Trim())'" | ||
| $request.Filter = $Filter.Trim() | ||
| } | ||
| } | ||
| if ($Limit -gt 0 -and $PageSize -gt $Limit) { | ||
| Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with first page" -f $PageSize,$Limit) | ||
| $PageSize = $Limit | ||
| } | ||
| $request.PageSize = $PageSize | ||
| Write-Verbose $verbString | ||
| [int]$i = 1 | ||
| $overLimit = $false | ||
| do { | ||
| $result = $request.Execute() | ||
| if ($null -ne $result.Devices) { | ||
| $result.Devices | Add-Member -MemberType ScriptMethod -Name ToString -Value {$this.DeviceId} -PassThru -Force | ||
| } | ||
| $request.PageToken = $result.NextPageToken | ||
| [int]$retrieved = ($i + $result.Devices.Count) - 1 | ||
| Write-Verbose "Retrieved $retrieved Chrome devices..." | ||
| if ($Limit -gt 0 -and $retrieved -eq $Limit) { | ||
| Write-Verbose "Limit reached: $Limit" | ||
| $overLimit = $true | ||
| } | ||
| elseif ($Limit -gt 0 -and ($retrieved + $PageSize) -gt $Limit) { | ||
| $newPS = $Limit - $retrieved | ||
| Write-Verbose ("Reducing PageSize from {0} to {1} to meet limit with next page" -f $PageSize,$newPS) | ||
| $request.PageSize = $newPS | ||
| } | ||
| [int]$i = $i + $result.Devices.Count | ||
| } | ||
| until ($overLimit -or !$result.NextPageToken) | ||
| } | ||
| catch { | ||
| if ($ErrorActionPreference -eq 'Stop') { | ||
| $PSCmdlet.ThrowTerminatingError($_) | ||
| } | ||
| else { | ||
| Write-Error $_ | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.