Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #CONFIGURE==============
- #If false, will tell you what the script will do without actually doing it
- $production = $true
- #region JSS API Credentials
- $jssURL = "https://jss.domain.com:8443"
- $apiUser = "user"
- $apiPass = "password"
- #endregion
- #Smart Group of devices to update user
- $smartGroup = "Temp"
- #END CONFIGURE===============
- $jssCredential = New-Object System.Management.Automation.PSCredential ($apiUser, (ConvertTo-SecureString $apiPass -AsPlainText -Force))
- $usernameList = @()
- Function GetJSS($request) {
- Return Invoke-RestMethod -Uri $jssURL'/JSSResource/'$request -Credential $jssCredential -Method Get
- }
- Function ApplyUser {
- [CmdletBinding()]
- PARAM (
- [Parameter(Mandatory=$true)] $ipad,
- [Parameter(Mandatory=$true)] [string] $ipademail
- )
- $PostXML = "
- <mobile_device>
- <location>
- <email_address>$ipademail</email_address>
- </location>
- </mobile_device>
- "
- #write-host $PostXML
- #Write-Host "Uploading Command to JSS..."
- Invoke-RestMethod -Credential $jssCredential -Uri $jssURL'/JSSResource/mobiledevices/id/'$iPad -Method Put -Body $PostXML -ContentType "text/xml"
- }
- Function RetrieveIpadList {
- [CmdletBinding()]
- PARAM (
- [Parameter(Mandatory=$true)] $group
- )
- $rawdata = GetJSS("mobiledevicegroups/name/$group")
- $data = $rawData.SelectNodes('//mobile_device_group/mobile_devices/mobile_device')
- $ipadList = [System.Collections.ArrayList]@()
- foreach ($device in $data) {
- [Void]$ipadlist.Add($device.id)
- }
- Return $ipadList
- }
- Function RetrieveIpadDetails {
- [CmdletBinding()]
- PARAM (
- [Parameter(Mandatory=$true)] $id
- )
- $rawdata = GetJSS("mobiledevices/id/$id")
- $data = $rawData.SelectNodes('//mobile_device')
- Return $data
- }
- # Function to check if a student already exists in AD
- Function GetADEmail($checkThis)
- {
- $User = Get-ADUser -Filter {samAccountName -eq $checkThis} -Properties mail
- If ($User -eq $Null) { Return "" }
- Else { Return $User.mail }
- }
- $ipads = RetrieveIpadList -group $smartGroup
- Write-Host $ipads.Count "iPads in Group"
- foreach ($ipad in $ipads) {
- $ipadinfo = (RetrieveIpadDetails -id $ipad)
- if($ipadInfo.location.username) {
- $ademail = GetADEmail($ipadInfo.location.username)
- if($ademail) {
- if($production) {ApplyUser -ipad $ipad -ipademail $ademail}
- else {write-host Would apply $ademail to iPad ID $ipad}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement