Skip to content

Instantly share code, notes, and snippets.

@Agazoth
Last active April 20, 2018 06:45
Show Gist options
  • Save Agazoth/e5207bb56052cfece7eb64d13ff40b13 to your computer and use it in GitHub Desktop.
Save Agazoth/e5207bb56052cfece7eb64d13ff40b13 to your computer and use it in GitHub Desktop.
Get-CSPBilling
Import-Module PartnerCenterModule
Import-Module PSExcel
$Destination = 'C:\Billing'
$BillingFilename = '{0}-{1}-{2}Billing.xlsx'
$clientSecret = 'Your super secret string'
$CSPAppID = 'Your App GUID'
$CSPDomain = 'Your CSP Domain'
$clientSecretSecure = $clientSecret | ConvertTo-SecureString -AsPlainText -Force
Add-PCAuthentication -cspAppID $CSPAppID -cspDomain $CSPDomain -cspClientSecret $clientSecretSecure
$Latest = Get-PCInvoice -all | Select-Object -First 1
'Azure','Office' | ForEach-Object {
$Params = @{
invoiceid = $Latest.id
billingprovider = $_
invoicelineitemtype = "BillingLineItems"
}
$FilePath = Join-Path $Destination $($BillingFilename -f $(Get-Date $Latest.invoiceDate -uformat "%Y-%m-%d"),$Latest.id,$_)
Get-PCInvoiceLineItems @Params | Export-xlsx $FilePath
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment