Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- . ".\Out-Pastebin.ps1"
- <# Updated 20160404
- 20160812
- ~ Updated to pull custom CSV from FCC's new API site
- t Working on FreePBX function, next update will have it complete
- 20160404
- + Added log file statements
- ~ Changed inital question to new or compare, defaults to compare if not new
- - Removed compare question in favor of default
- 20160328
- + Added If statment for comparison question, as script must be run twice to have a comparison
- + Added While statment to compare $file and $file2 to see if they are the same file, and ask for a new $file2 if true
- + Added subtraction of 1 from count reports (see ending Write-Hosts in the Delta and Primary If statement)
- 20160321
- ~ Reverted back to if statements instead of functions that just broke everything.
- #>
- $date = Get-Date -Format yyyyMMdd
- $logFile = ".\FCCListLog.log"
- $tmCIDN = ".\TelemarketingCIDN.csv"
- $tmABPN = ".\TelemarketingABPN.csv"
- $tmTemp = ".\Telemarketing-Temp"
- $tmDelta = ".\Telemarketing_RoboCall_Weekly_Data_Deltas-$date.csv"
- $tmDeltaList = ".\Telemarketing_RoboCall_Weekly_Data_List_Deltas-$date.csv"
- $tmMaster = ".\Telemarketing_RoboCall_Weekly_Data_Primary-$date.csv"
- $tmMasterList = ".\Telemarketing_RoboCall_Weekly_Data_List_Primary-$date.csv"
- If (Test-Path $tmCIDN) { Remove-Item $tmCIDN }
- If (Test-Path $tmABPN) { Remove-Item $tmABPN }
- If (Test-Path $tmTemp) { Remove-Item $tmTemp }
- If (!(Test-Path $logFile)) { New-Item $logFile -ItemType file }
- # Gives us the Open File dialog
- Function Get-FileName($initialDirectory)
- {
- [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |
- Out-Null
- $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
- $OpenFileDialog.initialDirectory = $initialDirectory
- $OpenFileDialog.filter = "CSV files (*.csv)| *.csv"
- $OpenFileDialog.ShowDialog() | Out-Null
- $OpenFileDialog.filename
- } #end function Get-FileName
- # Formatting function to transpose 200 numbers in the column to rows
- Function _Transpose($inpFile) {
- If ($inpFile -like "*Delta*") {
- Write-Output "Transpose Using Delta"
- $inpFile = $tmDeltaList
- $outFile = $tmDelta
- } Else {
- Write-Output "Transpose Using Primary"
- $inpFile = $tmTemp
- $outFile = $tmMaster
- }
- $tmTransposeTemp = ".\tmTransposeTemp.csv"
- Write-Output "Creating $tmTransposeTemp"
- Copy-Item $inpFile -Destination $tmTransposeTemp
- # Create file header for Google Contacts import
- $replace = "Name,Given Name,Additional Name,Family Name,Yomi Name,Given Name Yomi,Additional Name Yomi,Family Name Yomi,Name Prefix,Name Suffix,Initials,Nickname,Short Name,Maiden Name,Birthday,Gender,Location,Billing Information,Directory Server,Mileage,Occupation,Hobby,Sensitivity,Priority,Subject,Notes,Group Membership,Phone 1 - Type,Phone 1 - Value" | Out-File $outFile -Append
- $number = 0
- $letter = 65
- $round = 0
- $firstLine = (Import-CSV $tmTransposeTemp) | Select -First 2
- # Will error and stop when it tries to import a null into an array, which is kinda what we want. Should really find a clean exit.
- While ($firstLine[1] -ne $null) {
- # Create index for Spam contacts (Spam A0..Z9)
- If ($number -eq 100) { $number = 0 }
- If ($letter -eq 90) { $letter = 65 }
- if ($round -le 100) {
- $index = [char]$letter + $number.ToString("00")
- $number++
- } else {
- $letter++
- $index = [char]$letter + $number.ToString("00")
- $number++
- $round = 0
- }
- #Write-Output "Spam $index - $($firstLine[0].List)"
- $round++
- $batch = 200
- (Import-CSV $tmTransposeTemp) | Select -First $batch | Export-CSV $tmTemp -NoTypeInformation
- $replace = @(Get-Content $tmTemp) -Join ","
- $replace = $replace -replace '"','' -replace ',',' ::: '
- If ($inpFile -like "*Delta*") {
- $insert = "Spam Delta $index $date,Spam,,,,,,,,,,,,,,,,,,,,,,,,,* My Contacts ::: Spammers,Mobile,"
- } Else {
- $insert = "Spam $index,Spam,,,,,,,,,,,,,,,,,,,,,,,,,* My Contacts ::: Spammers,Mobile,"
- }
- $replace -replace 'Caller ID Number',$insert -replace ', ::: ',',' | Out-File $outFile -Append
- Write-Output "$($insert)$($firstLine[0].'Caller ID Number')"
- (Import-CSV $tmTransposeTemp) | Select -Skip $batch | Export-CSV $tmTemp -NoTypeInformation
- Move $tmTemp -Destination $tmTransposeTemp -Force
- $firstLine = (Import-CSV $tmTransposeTemp) | Select -First 2
- $batch += 200
- }
- If (Test-Path $tmTransposeTemp) { Remove-Item $tmTransposeTemp }
- If (Test-Path $tmTemp) { Remove-Item $tmTemp }
- }
- Function _FreePBX {
- Import-CSV $tmMasterList
- field 1 = numbers
- field 2 = description
- all descriptions = telemarketing
- }
- $start = Get-Date -format "HH:mm:ss"
- # Get the latest list from the FCC website
- Read-Host -Prompt "Get New list or Compare? [N or C]" -OutVariable new
- if ($new -like "n") {
- $url = "https://opendata.fcc.gov/api/views/tkbm-mngi/rows.csv?accessType=DOWNLOAD"
- $file = "Telemarketing_RoboCall_Weekly_Data-$date.csv"
- Write-Host $file -ForegroundColor Yellow
- If (!(Get-Item -Path .\Telemarketing_RoboCall_Weekly_Data-$date.csv)) {
- Invoke-WebRequest -Uri $url -OutFile $file -ErrorAction Stop
- }
- $tmMaster = ".\Telemarketing_RoboCall_Weekly_Data_Primary-$date.csv"
- $tmMasterList = ".\Telemarketing_RoboCall_Weekly_Data_List_Primary-$date.csv"
- } else {
- $new = "c"
- $file = Get-FileName -initialDirectory "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
- }
- # Delta (Compare) and Primary list generators
- if ($new -like "c") {
- $file2 = Get-FileName -initialDirectory "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
- While ($file -eq $file2) {
- Write-Host "Duplicate file selected, please select a new file to compare to..." -ForegroundColor Red
- $file2 = Get-FileName -initialDirectory "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
- }
- $comp1 = Import-CSV $file
- $comp2 = Import-CSV $file2
- Write-Host "Comparing files..." -ForegroundColor Yellow
- Compare-Object $comp1 $comp2 -Property "List" | Export-CSV ".\tmDeltas-$date.csv" -NoTypeInformation
- (Import-CSV ".\tmDeltas-$date.csv") | Select "List" | Export-CSV $tmDeltaList -NoTypeInformation
- Write-Host "Transposing..." -ForegroundColor Yellow
- _Transpose("Delta")
- Remove-Item ".\tmDeltas-$date.csv"
- $tmDeltaCount = (Get-Content $tmDeltaList) | Measure-Object -Line
- $tmDeltaContacts = (Get-Content $tmDelta) | Measure-Object -Line
- $tmMasterCount = (Get-Content $tmMasterList) | Measure-Object -Line
- $PastebinContent = (Get-Content $tmDelta)
- #Out-Pastebin -InputObject $PastebinContent -PasteTitle "FCC Telemarketer and RoboCall Blacklist - Deltas $date" -ExpiresIn N -Visibility Public -OpenInBrowser -OutVariable PastedURI
- $log = "$date - Primary list is $($tmMasterCount.Lines) numbers, and the Deltas from last file are $($tmDeltaCount.Lines) in $($tmDeltaContacts.Lines), URL $PastedURI"
- Write-Host $log -ForegroundColor Yellow
- $log | Out-File $logFile -Append
- } else {
- Write-Output "Creating $tmCIDN"
- Import-CSV $file | Select "Caller ID Number" | Export-CSV $tmCIDN –NoTypeInformation
- (Import-CSV $tmCIDN) | Sort "Caller ID Number" -Unique | Export-CSV $tmCIDN -NoTypeInformation
- Write-Output "Creating $tmABPN"
- Import-CSV $file | Select "Advertiser Business Number" | Export-CSV $tmABPN –NoTypeInformation
- (Import-CSV $tmABPN) | Sort "Advertiser Business Number" -Unique | Export-CSV $tmABPN -NoTypeInformation
- $gcCIDN = Get-Content $tmCIDN
- $gcABPN = Get-Content $tmABPN
- Add-Content $tmTemp $gcCIDN
- Add-Content $tmTemp $gcABPN
- Write-Output "Creating $tmTemp"
- (Import-CSV $tmTemp) | Sort "Caller ID Number" -Unique | Where-Object {$_ -notlike "*Advertiser*"} | Export-CSV $tmTemp -NoTypeInformation
- Get-Content $tmTemp | Select -Skip 1 | Set-Content $tmMasterList
- #(Import-Csv $tmMasterList) | Select-Object @{ expression={$_.'-'}; label='List' } | Export-Csv $tmMasterList -NoTypeInformation
- #Remove-Item $tmTemp
- Write-Output "Transposing..."
- _Transpose("Master")
- If (Test-Path $tmCIDN) { Remove-Item $tmCIDN }
- If (Test-Path $tmABPN) { Remove-Item $tmABPN }
- $tmMasterCount = (Get-Content $tmMasterList) | Measure-Object -Line
- $tmMasterContacts = (Get-Content $tmMaster) | Measure-Object -Line
- $PastebinContent = (Get-Content $tmMaster)
- #Out-Pastebin -InputObject $PastebinContent -PasteTitle "FCC Telemarketer and RoboCall Blacklist - Full $date" -ExpiresIn N -Visibility Public -OpenInBrowser -OutVariable PastedURI
- $log = "$date - Primary list is $($tmMasterCount.Lines) numbers, and $($tmMasterContacts.Lines) contacts, URL $PastedURI"
- Write-Host $log -ForegroundColor Yellow
- $log | Out-File $logFile -Append
- }
- $end = Get-Date -format "HH:mm:ss"
- Write-Output "Started at $($start)"
- Write-Output "Finished at $($end)"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement