diff --git a/Get-ListOfTaggedDevices.ps1 b/Get-ListOfTaggedDevices.ps1 new file mode 100644 index 0000000..606adc2 --- /dev/null +++ b/Get-ListOfTaggedDevices.ps1 @@ -0,0 +1,47 @@ +<# +.SYNOPSIS + Creates List of Devices that have a particular tag in AirWatch +.DESCRIPTION + This script displays all tags in the Organization group, allowing the user to select a tag. All of the devices with that tag are exported to a CSV file named for that tag. + + This PowerShell script is PowerShell Core compliant and was written with Visual Studio Code on a Mac. It has been tested on Windows and Mac, but should also run on Linux. + Setup: + This script takes an input of serial numbers from a CSV file. Sample Included. + It also takes a config file, which houses the API Host, API key and Organization Group ID for your AirWatch environment. + A sample file has been included, if you don't have one the script prompt fpr the values and will create it. + +.PARAMETER + + Information you will need to use this script: + userName - An AirWatch account in the tenant is being queried. This user must have the API role at a minimum. Can be basic or directory user. + password - The password that is used by the user specified in the username parameter + tenantAPIKey - This is the REST API key that is generated in the AirWatch Console. You locate this key at All Settings -> Advanced -> API -> REST, and you will find the key in the API Key field. If it is not there you may need override the settings and Enable API Access + airwatchServer - This will be the fully qualified domain name of your AirWatch API server, without the https://. All of the REST endpoints start with a forward slash (/) so do not include that either. + organizationGroupId - This will be the organization group Id in the AirWatch console. Not the group name, but the ID. + +.INPUTS + AirWatchConfig.json +.OUTPUTS + Outputs a CSV file with Devices that have the selected tag. +.NOTES + Version: 1.4 + Author: Joshua Clark @MrTechGadget + Creation Date: 09/06/2017 + Update Date: 07/30/2021 + Site: https://github.com/MrTechGadget/aw-bulkdevices-script + +.EXAMPLE + Get-ListOfTaggedDevices.ps1 +#> + +Import-Module .\PSairwatch.psm1 + +<# Start of Script #> +$TagList = Get-Tags +$SelectedTag = Select-Tag $TagList +$TagName = $TagList.keys | Where-Object {$TagList["$_"] -eq [string]$SelectedTag} +$Devices = Get-TaggedDevice $SelectedTag +$DeviceJSON = Set-AddTagJSON $Devices +$DeviceDetails = Get-DeviceDetails $DeviceJSON +$DeviceDetails | Export-Csv -Path "${TagName}.csv" +Write-Host "All Devices with ${TagName} saved to ${TagName}.csv" diff --git a/PSairwatch.psm1 b/PSairwatch.psm1 index 6b3449e..cb75db9 100644 --- a/PSairwatch.psm1 +++ b/PSairwatch.psm1 @@ -16,11 +16,11 @@ .OUTPUTS None .NOTES - Version: 2.9.0 + Version: 2.10.0 Author: Joshua Clark @MrTechGadget Source: https://github.com/MrTechGadget/aw-bulkdevices-script Creation Date: 05/22/2018 - Update Date: 01/20/2021 + Update Date: 07/30/2021 .EXAMPLE $ScriptPath = Split-Path $MyInvocation.MyCommand.Path -Parent @@ -321,6 +321,19 @@ Function Get-DeviceDetails { } +Function Get-TaggedDevice { + Param([string]$SelectedTag) + + $endpoint = "mdm/tags/${SelectedTag}/devices?" + $webReturn = Send-Get $endpoint + $s = @() + foreach ($device in $webReturn.Device) { + $s += $device.DeviceId + Write-Verbose $device.DeviceId + } + return $s +} + Function Send-Get { Param( [Parameter(Mandatory=$True,HelpMessage="Rest Endpoint for Get, after https://airwatchServer/api/")]