General cleanup of current code

General cleanup of current code
This commit is contained in:
Zack T
2018-02-23 10:22:04 -07:00
parent e5afea0e61
commit 9a615e26dc

View File

@@ -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 = "<?xml version='1.0' encoding='UTF-8'?><computer_extension_attribute><input_type><type>Pop-up Menu</type><popup_choices><choice>default</choice></popup_choices></input_type></computer_extension_attribute>"
[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
}
}