Last active
July 23, 2020 03:21
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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