Functions/Invoke-AdminPortalCreation.ps1
|
function Invoke-AdminPortalCreation { [CmdletBinding()] param ( [Parameter()] [switch] $OpenInBrowser, [Parameter()] [switch] $Offline, [Parameter()] [switch] $DummyData, [Parameter()] [string] $CsvFile ) function Save-Files { [CmdletBinding()] param ( [Parameter(Mandatory)] [string] $FolderPath ) $RelPath = Join-Path "$($PSScriptRoot)" "\..\Resources\AdminPortal" -Resolve $Files = Get-ChildItem $RelPath -Recurse -File $Files.FullName | ForEach-Object { # $_ -replace "$($PSScriptRoot)\..\Resources\AdminPortal", "" $Outpath = Join-Path $FolderPath $_.Replace($RelPath, "") Copy-Item $_ $Outpath -Force } } function Write-CustomerRow { [CmdletBinding()] param ( [Parameter(Mandatory)] $Customer ) # <button title="fav_$($Customer.CustomerId)" class="FavoriteButton" value="fav_$($Customer.CustomerId)">Favorite</button> @" <div class=`"CustomerRow`" id="row_$($Customer.CustomerId)"> <div class=`"CustomerName`">$($Customer.Name)</div> <div class=`"CustomerInfo`"> Customer Domain: $($Customer.Domain)<br><br>Tenant ID: $($Customer.CustomerId)<br><br> <a href=`"https://partner.microsoft.com/dashboard/v2/customers/$($Customer.CustomerId)/subscriptions/`"><img src="img/Partner.svg">Partner Center</a> - <a href=`"https://partner.microsoft.com/dashboard/v2/customers/$($Customer.CustomerId)/devices`"><img src="img/Autopilot.svg">Devices</a> - <a href=`"https://partner.microsoft.com/en-us/dashboard/commerce2/customers/$($Customer.CustomerId)/adminrelationships`"><img src="img/Agreements.svg">Adminrelationships</a><br> </div> <div class=`"CustomerLinks`"> <div><a href=`"https://entra.microsoft.com/$($Customer.domain)`"><img src="img/Entra.svg">Entra</a></div> <div><a href=`"https://Intune.microsoft.com/$($Customer.domain)`"><img src="img/Intune.svg">Intune</a></div> <div><a href=`"https://portal.azure.com/$($Customer.domain)`"><img src="img/azure.svg">Azure</a></div> <div><a href=`"https://portal.office.com/Partner/BeginClientSession.aspx?CTID=$($Customer.CustomerId)&CSDEST=o365admincenter`"><img src="img/Admin.svg">MS365 Admin</a></div> <div><a href=`"https://admin.exchange.microsoft.com/?delegatedOrg=$($Customer.domain)#/homepage`"><img src="img/Exchange.svg">Exchange Admin</a></div> <div><a href=`"https://admin.microsoft.com/Partner/beginclientsession.aspx?CTID=$($Customer.CustomerId)&CSDEST=SharePoint/`"><img src="img/SharePoint.svg">SharePoint Admin</a></div> </div> </div> "@ } $outputPath = "C:\Temp\AdminPortal" # $outputPathImages = Join-Path $outputPath "img" if ($DummyData) { $CustomerData = @" "Name","Domain","CustomerId" "De Zon","dezon.onmicrosoft.com","e815effe-4098-47bf-8fe0-99dab45ee4ea" "Onze planeet Aarde","onzeplaneetaarde.onmicrosoft.com","b63d4967-8f1f-4d5b-a9b6-164a4aae47e1" "De planeet Mars","deplaneetmars.onmicrosoft.com","85620ccd-32a7-4407-924a-d7495b1ef2a3" "De planeet Venus","deplaneetvenus.onmicrosoft.com","d24deaea-c96f-470c-8f68-a7252fc30fb9" "De planeet Saturnus","deplaneetsaturnus.onmicrosoft.com","f1be15b4-0c75-4327-b9a5-b6a6746bfa17" "De planeet Uranus","deplaneeturanus.onmicrosoft.com","4959e05c-3ba7-47c8-8ece-e60b9d1957ab" "De planeet Pluto","deplaneetpluto.onmicrosoft.com","48273dfb-b310-4e28-ae67-9b01f92f9b12" "Een Ster","eenster.onmicrosoft.com","3debf136-6f12-4eac-ab3a-e0bba1de5cd6" "De planeet Jupiter","deplaneetjupiter.onmicrosoft.com","b5ee263e-8207-4ab9-84b3-2ed8c5fa37aa" "Zonnestelsel","zonnestelsel.onmicrosoft.com","1ec35423-62f8-403b-857f-b3de752edeac" "Het zwarte gat","hetzwartegat.onmicrosoft.com","edc912a9-5420-48dc-b010-ec236ec3d67e" "De Maan","demaan.onmicrosoft.com","fcad9d10-75a1-43b6-bdc9-53948eea317b" "Een andere maan van een andere planeet","eenanderemaanvaneenandereplaneet.onmicrosoft.com","a695488e-c09e-43d9-ba18-4d720712b60d" "Mercurius","mercurius.onmicrosoft.com","ece6170a-e387-474f-b777-36920576a2e2" "Oerknal","oerknal.onmicrosoft.com","4aca4736-bb84-4d72-b6bd-497ee110710a" "@ $Customers = ConvertFrom-Csv $CustomerData | Sort-Object Name } elseif ($CsvFile) { $csvCustomers = Import-Csv $CsvFile | Sort-Object "Company name" Write-Verbose ($csvCustomers | Format-Table -AutoSize | Out-String) $Customers = @() $csvCustomers | ForEach-Object { $obj = [PSCustomObject]@{ CustomerId = $_."Microsoft ID" Domain = $_."Primary domain name" Name = $_."Company name" RelationshipToPartner = $_.Relationship } $Customers += $obj } # $Customers | Format-Table -AutoSize # $result | ConvertTo-Json | Out-File C:\Temp\AdminPortal\PartnerTenants.json -Force } else { if (!($Offline)) { if (!(Get-PartnerContext)) { Connect-PartnerCenter -UseDeviceAuthentication } $Customers_notunique = Get-PartnerCustomer | Sort-Object -Property Name $Customers = @() $Customers_notunique | ForEach-Object { if ($Customers.CustomerId -notcontains $_.CustomerId) { $Customers += $_ } } if ($Customers.Count -eq 0) { throw "no customers found" } } } $sb = [System.Text.StringBuilder]::new() $baseHtml = @" <!DOCTYPE html> <html lang=nl> <head> <title>Parter Admin Portal</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <base target="_blank"> <link rel="stylesheet" href="style.css"> </head> <body> <main class="table"> <!-- <div class="table_div" id="fav_div"> <section class="table__header"> <h1>Favorites</h1> </section> <section class="table__body"> <table class="Customers FavoriteCustomers"> <tbody id="fav_table_body"> </tbody> </table> </section> </div> --> <div class="table_div"> <section class="table__header"> <div><h1>All Customers (<span id="customercount">-</span>)</h1></div> <div class="searchbox"> <input type="text" name="CustomerSearch" id="CustomerSearch" placeholder="Press 'F' to search..."> </div> <div class="date"><a href="https://partner.microsoft.com/dashboard/v2/customers/list">Partner Center</a></div> <div class="date">Page generated on: <span id="page_date">-</span> (<span id="page_age">-</span>)</div> </section> <section class="table__body"> <div id="default_table_body" class="Customers"> </div> </section> </div> <div class="more_scrolling_to_do"></div> </main> <script src="PartnerTenants.js"></script> <script src="script.js"></script> </body> </html> "@ $sb.AppendLine($baseHtml) | Out-Null if (-NOT (Test-Path -Path $outputPath)) { Write-Output "Creating directory: $outputPath" New-Item -Path $outputPath -ItemType "Directory" -Force } Save-Files -FolderPath $outputPath $OutFile = Join-Path -Path $outputPath -ChildPath "AdminPortal.html" $sb.ToString() | Out-File $OutFile $OutFile if ($OpenInBrowser) { Start-Process "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" -ArgumentList "$OutFile" } $customerJS = "" $customerJS += "const customers = " $customerJS += $Customers | ConvertTo-Json $customerJS += @" localStorage.setItem('customers', JSON.stringify(customers)) localStorage.setItem('customers_timestamp', $([int][double]::Parse((Get-Date (Get-Date).touniversaltime() -UFormat %s)))) "@ if (!($Offline) -or $CsvFile) { Write-Verbose "Output to json and js files" $customerJS | Out-File (Join-Path -Path $outputPath -ChildPath "PartnerTenants.js") $Customers | ConvertTo-Json | Out-File (Join-Path -Path $outputPath -ChildPath "PartnerTenants.json") } } |