Partner-Center-PowerShell icon indicating copy to clipboard operation
Partner-Center-PowerShell copied to clipboard

Querying users attached to a subscription.

Open solipsist01 opened this issue 5 years ago • 0 comments

For reporting purposes i'm using the code below. However, this takes alot of time.

i have to check, per user, which license the user has. I'd rather query the license, and then get a dump of all users which are connected to this license.

Similar to the cmdlet "Get-MsolUser" from MSOnline

Am i missing something obvious by any chance? if not, i'd like to file this as a feature request.

$customers = get-partnercustomer
$PlanArr = @()
foreach ($customer in $customers) {

    $users = Get-PartnerCustomerUser -CustomerId $customer.CustomerId

    foreach ($user in $users) {
        echo "$((get-date).ToString('T')) Customer: $($customer.name) - User: $($user.DisplayName)"
        $plans = Get-PartnerCustomerUserLicense -CustomerId $customer.CustomerId -UserId $user.userid
            foreach ($plan in $plans) {
                $PlanObj = new-object System.Object
                $PlanObj | add-member -memberType NoteProperty -Name Customer -Value $customer.name
                $PlanObj | add-member -memberType NoteProperty -Name Domain -Value $customer.domain
                $PlanObj | add-member -memberType NoteProperty -Name User -Value $user.UserPrincipalName
                $PlanObj | add-member -memberType NoteProperty -Name License -Value $plan.Name
                $PlanArr += $PlanObj
            }
    }
}

solipsist01 avatar Jul 28 '20 07:07 solipsist01