Skip to content

Instantly share code, notes, and snippets.

@hansgafriedzal
Last active July 23, 2020 03:21
Show Gist options
  • Save hansgafriedzal/c7dfdc5a770b5f827dbc6ea69c7d32eb to your computer and use it in GitHub Desktop.
Save hansgafriedzal/c7dfdc5a770b5f827dbc6ea69c7d32eb to your computer and use it in GitHub Desktop.
Append response from Get-MsolSubscription into a csv file in the desktop. Call Connect-MsolService before running this.
function Log-MsolSubscription
{
begin
{
$timestamp = Get-Date -format "yyyyMMddHHmmss"
$executionName = $MyInvocation.MyCommand
$logFilename = "$($timestamp)_$(gc env:computername)_$($executionName)"
$logPath = "$([Environment]::GetFolderPath("Desktop"))\$executionName\$logFilename.log"
Start-Transcript -Path $logPath > $null
}
process
{
$datetime = Get-Date -format 'dd-MMM-yyyy H:mm:ss'
$csvPath = "$([Environment]::GetFolderPath("Desktop"))\$executionName.csv"
$initialDomain = (Get-MsolCompanyInformation).InitialDomain
$report = Get-MsolSubscription | %{
[pscustomobject] @{
CreatedBy = gc env:computername
Created = $datetime
InitialDomain = $initialDomain
SkuPartNumber = $_.SkuPartNumber
TotalLicenses = $_.TotalLicenses
}
}
$report | fl *
}
end
{
$report | Export-Csv $csvPath -NoTypeInformation -Append
Stop-Transcript > $null
}
}
Log-MsolSubscription
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment