Skip to content

Commit

Permalink
Updated itg contact pull to support >1000 contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjantzen committed Dec 13, 2022
1 parent 7477a78 commit 13f69a0
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 8 deletions.
54 changes: 49 additions & 5 deletions User Audit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,18 @@ if ($FullContactList.Error) {
$FullContactList = $FullContactList.data
}

if ($FullContactList.Count -gt 999) {
$FullContactList = @()
$i = 1
while ($i -le 10 -and ($FullContactList | Measure-Object).Count -eq (($i-1) * 500)) {
$FullContactList += (Get-ITGlueContacts -page_size 500 -page_number $i -organization_id $OrgID).data
Write-Host "- Got contact set $i"
$TotalContacts = ($FullContactList | Measure-Object).Count
Write-Host "- Total: $TotalContacts"
$i++
}
}

# Get the contact types list from IT Glue for later
$FullContactTypes = (Get-ITGlueContactTypes -sort "name").data
$ContactTypes = @()
Expand Down Expand Up @@ -520,7 +532,15 @@ if ($RunPreCleanup -eq 'Yes') {

# Re-get the contact list
Write-Host "Getting an updated contact list from IT Glue."
$FullContactList = (Get-ITGlueContacts -page_size 1000 -organization_id $OrgID).data
$FullContactList = @()
$i = 1
while ($i -le 10 -and ($FullContactList | Measure-Object).Count -eq (($i-1) * 500)) {
$FullContactList += (Get-ITGlueContacts -page_size 500 -page_number $i -organization_id $OrgID).data
Write-Host "- Got contact set $i"
$TotalContacts = ($FullContactList | Measure-Object).Count
Write-Host "- Total: $TotalContacts"
$i++
}
Write-Host "===================================" -ForegroundColor Blue
}

Expand Down Expand Up @@ -580,7 +600,15 @@ if (($FixContactEmails | Measure-Object).count -gt 0 -or ($FixContactPhone | Mea

# Re-get the contact list
Write-Host "Getting an updated contact list from IT Glue."
$FullContactList = (Get-ITGlueContacts -page_size 1000 -organization_id $OrgID).data
$FullContactList = @()
$i = 1
while ($i -le 10 -and ($FullContactList | Measure-Object).Count -eq (($i-1) * 500)) {
$FullContactList += (Get-ITGlueContacts -page_size 500 -page_number $i -organization_id $OrgID).data
Write-Host "- Got contact set $i"
$TotalContacts = ($FullContactList | Measure-Object).Count
Write-Host "- Total: $TotalContacts"
$i++
}
Write-Host "===================================" -ForegroundColor Blue

} else {
Expand Down Expand Up @@ -3095,7 +3123,15 @@ if ($FullMatches) {

# Re-get the contact list (since we likely just updated the types)
Write-Host "Getting an updated contact list from IT Glue."
$FullContactList = (Get-ITGlueContacts -page_size 1000 -organization_id $OrgID).data
$FullContactList = @()
$i = 1
while ($i -le 10 -and ($FullContactList | Measure-Object).Count -eq (($i-1) * 500)) {
$FullContactList += (Get-ITGlueContacts -page_size 500 -page_number $i -organization_id $OrgID).data
Write-Host "- Got contact set $i"
$TotalContacts = ($FullContactList | Measure-Object).Count
Write-Host "- Total: $TotalContacts"
$i++
}
$FullContactList.attributes | Add-Member -MemberType NoteProperty -Name ID -Value $null
$FullContactList | ForEach-Object { $_.attributes.id = $_.id }
$EmployeeContacts = $FullContactList.attributes | Where-Object {$_."contact-type-name" -in $EmployeeContactTypes -or !$_."contact-type-name"}
Expand All @@ -3106,7 +3142,7 @@ Write-Host "===================================" -ForegroundColor Blue
New-Item -ItemType Directory -Force -Path "C:\billing_history" | Out-Null
$Month = Get-Date -Format "MM"
$Year = Get-Date -Format "yyyy"
$historyContacts = (Get-ITGlueContacts -page_size 1000 -organization_id $OrgID).data | ConvertTo-Json
$historyContacts = $FullContactList | ConvertTo-Json
if (!$config) {
$historyPath = "C:\billing_history\contacts_$($Month)_$($Year).json"
} else {
Expand Down Expand Up @@ -3323,7 +3359,15 @@ if ($ExportChoice -eq 'Yes') {
}

# Get a fresh list of contacts from IT Glue
$FullContactList = (Get-ITGlueContacts -page_size 1000 -organization_id $OrgID).data
$FullContactList = @()
$i = 1
while ($i -le 10 -and ($FullContactList | Measure-Object).Count -eq (($i-1) * 500)) {
$FullContactList += (Get-ITGlueContacts -page_size 500 -page_number $i -organization_id $OrgID).data
Write-Host "- Got contact set $i"
$TotalContacts = ($FullContactList | Measure-Object).Count
Write-Host "- Total: $TotalContacts"
$i++
}
$FullContactList.attributes | Add-Member -MemberType NoteProperty -Name ID -Value $null
$FullContactList | ForEach-Object { $_.attributes.id = $_.id }
if ($CheckChanges) {
Expand Down
41 changes: 39 additions & 2 deletions User_Billing_Update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,18 @@ if ($FullContactList.Error) {
$FullContactList = $FullContactList.data
}

if ($FullContactList.Count -gt 999) {
$FullContactList = @()
$i = 1
while ($i -le 10 -and ($FullContactList | Measure-Object).Count -eq (($i-1) * 500)) {
$FullContactList += (Get-ITGlueContacts -page_size 500 -page_number $i -organization_id $OrgID).data
Write-Host "- Got contact set $i"
$TotalContacts = ($FullContactList | Measure-Object).Count
Write-Host "- Total: $TotalContacts"
$i++
}
}

$ContactCount = ($FullContactList | Measure-Object).Count
Write-Host "Got the contact data from IT Glue. $ContactCount contacts were found."
Write-PSFMessage -Level Verbose -Message "Got '$($ContactCount)' contacts from IT Glue."
Expand Down Expand Up @@ -1503,6 +1515,23 @@ if ($UserAudit) {
$HTMLBody += '</ul><br />'
}

if (($DuplicateIDs | Measure-Object).Count -gt 0) {
$HTMLBody += '<br />
<p style="font-family: sans-serif; font-size: 18px; font-weight: normal; margin: 0; Margin-bottom: 15px;"><strong>Possible Duplicate ITG Contacts Found</strong></p>
<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;">
The following ITG Contacts may be duplicates. Please review and remove/combine any contacts where necessary.
</p>
<ul>
'

foreach ($ID in $DuplicateIDs) {
$Contact = $FullContactList | Where-Object { $_.id -eq $ID }
$PrimaryEmail = ($Contact.attributes."contact-emails" | Where-Object {$_.primary -eq $true}).value
$HTMLBody += "<li><u>$($Contact.attributes.Name)</u> ($($Contact.attributes.'contact-type-name')) (Location: $($Contact.attributes.'location-name')) (Email: $($PrimaryEmail)) (URL: $($Contact.attributes.'resource-url'))</li>"
}
$HTMLBody += '</ul><br />'
}

$EmailIntro = "Contact discrepancies were found at <strong>$OrgFullName</strong>. These will affect billing. Please review each and fix. A tabular summary is at the end of this email.
<br /><br />Please correct these issues before <strong>$DueDate</strong>, at that time billing will be updated based on the ITG contact list.
Note that any issues you ignore now will not be reported on next month."
Expand Down Expand Up @@ -1563,7 +1592,15 @@ if ($BillingUpdate) {
}

# Get a fresh list of contacts from IT Glue
$FullContactList = (Get-ITGlueContacts -page_size 1000 -organization_id $OrgID).data
$FullContactList = @()
$i = 1
while ($i -le 10 -and ($FullContactList | Measure-Object).Count -eq (($i-1) * 500)) {
$FullContactList += (Get-ITGlueContacts -page_size 500 -page_number $i -organization_id $OrgID).data
Write-Host "- Got contact set $i"
$TotalContacts = ($FullContactList | Measure-Object).Count
Write-Host "- Total: $TotalContacts"
$i++
}
$FullContactList.attributes | Add-Member -MemberType NoteProperty -Name ID -Value $null
$FullContactList | ForEach-Object { $_.attributes.id = $_.id }
Write-PSFMessage -Level Verbose -Message "Got $(($FullContactList | Measure-Object).Count) contacts from IT Glue."
Expand All @@ -1572,7 +1609,7 @@ if ($BillingUpdate) {
New-Item -ItemType Directory -Force -Path "C:\billing_history" | Out-Null
$Month = Get-Date -Format "MM"
$Year = Get-Date -Format "yyyy"
$historyContacts = (Get-ITGlueContacts -page_size 1000 -organization_id $OrgID).data | ConvertTo-Json
$historyContacts = $FullContactList | ConvertTo-Json
if (!$config) {
$historyPath = "C:\billing_history\contacts_$($Month)_$($Year).json"
} else {
Expand Down
2 changes: 1 addition & 1 deletion currentversion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.14.0
2.15.0

0 comments on commit 13f69a0

Please sign in to comment.