diff --git a/Jamf Pro/Admin Tools/jamf_ea_Site.ps1 b/Jamf Pro/Admin Tools/jamf_ea_Site.ps1 index f721a12..243de7c 100644 --- a/Jamf Pro/Admin Tools/jamf_ea_Site.ps1 +++ b/Jamf Pro/Admin Tools/jamf_ea_Site.ps1 @@ -8,45 +8,55 @@ Description: This script will basically update an EA to the value of the comput #> +# ============================================================ +# Define Variables +# ============================================================ + +# Setup Credentials $jamfAPIUser = "" $jamfAPIPassword = ConvertTo-SecureString -String "" -AsPlainText -Force $APIcredentials = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $jamfAPIUser, $jamfAPIPassword +# Setup API URLs $jamfPS="https://newjss.company.com:8443" $getSites="${jamfPS}/JSSResource/sites" $getComputerEA="${jamfPS}/JSSResource/computerextensionattributes/id/43" -#$mobileEA="${jamfPS}/JSSResource/mobiledeviceextensionattributes/name/Jamf%20Site" +$getMobileEA="${jamfPS}/JSSResource/mobiledeviceextensionattributes/id/" $getComputers="${jamfPS}/JSSResource/computers" $computersGeneral="${jamPS}/JSSResource/computers/id/subset/General" $computersEA="${jamPS}/JSSResource/computers/id/subset/extension_attribute" -#[xml]$template_ComputerEA = "Pop-up Menudefault" - -[xml]$template_ComputerEA = $objectComputerEA.InnerXml +# ============================================================ +# Functions +# ============================================================ function updateSiteList { -$objectOfSites = Invoke-RestMethod -Uri $getSites -Method Get -Credential $APIcredentials -$objectComputerEA = Invoke-RestMethod -Uri $getComputerEA -Method Get -Credential $APIcredentials +$objectOf_Sites = Invoke-RestMethod -Uri $getSites -Method Get -Credential $APIcredentials +$objectOf_ComputerEA = Invoke-RestMethod -Uri $getComputerEA -Method Get -Credential $APIcredentials +[xml]$xml_ComputerEA = $objectOfComputerEA.InnerXml -if ( $objectOfSites.sites.site.Count -eq $($objectComputerEA.computer_extension_attribute.input_type.popup_choices.choice.Count - 1) ) { + +if ( $objectOf_Sites.sites.site.Count -eq $($objectOf_ComputerEA.computer_extension_attribute.input_type.popup_choices.choice.Count - 1) ) { Write-Host "Site count equal Computer EA Choice Count" Write-Host "Presuming these are up to date" } else { Write-Host "Site count does not equal Computer EA Choice Count" - $SiteList = $objectOfSites.sites.site | ForEach-Object {$_.Name} - $missingChoices = $(Compare-Object -ReferenceObject $($objectOfSites.sites.site | ForEach-Object {$_.Name}) -DifferenceObject $objectComputerEA.computer_extension_attribute.input_type.popup_choices.choice) | ForEach-Object {$_.InputObject} + $SiteList = $objectOf_Sites.sites.site | ForEach-Object {$_.Name} + $missingChoices = $(Compare-Object -ReferenceObject $($objectOf_Sites.sites.site | ForEach-Object {$_.Name}) -DifferenceObject $objectOf_ComputerEA.computer_extension_attribute.input_type.popup_choices.choice) | ForEach-Object {$_.InputObject} $missingChoices ForEach ( $choice in $missingChoices ) { Write-Host $choice - $newElement = $template_ComputerEA.CreateElement("choice") + $newElement = $xml_ComputerEA.CreateElement("choice") $newElement.InnerXml = $choice - $template_ComputerEA.SelectSingleNode("//popup_choices").AppendChild($newElement) - Invoke-RestMethod -Uri $getComputerEA -Method Put -Credential $APIcredentials -Body $template_ComputerEA + $xml_ComputerEA.SelectSingleNode("//popup_choices").AppendChild($newElement) + } + + #Invoke-RestMethod -Uri $getComputerEA -Method Put -Credential $APIcredentials -Body $template_ComputerEA } }