Link to home
Start Free TrialLog in
Avatar of Ron Shorts
Ron ShortsFlag for United States of America

asked on

Powershell for loop script for O365 licenses

Hi Experts,

I'm trying to create a powershell script, with a for loop to pull a list of users from a list and get it into a .csv file for a list of users to export Office 365 licenses.

The script I have is only outputting the last user in the list I have.  

Can anyone help with this?

$list = import-csv .\list.csv 

foreach ($User in $List) 
{
Get-MSOLUser -UserPrincipalName $User.userprincipalname | where {$_.isLicensed -eq $true} |select DisplayName,userprincipalname,islicensed,{$_.Licenses.AccountSkuId}| Export-CSV .\O365UserList.csv –NoTypeInformation 
}

Open in new window

SOLUTION
Avatar of Vasil Michev (MVP)
Vasil Michev (MVP)
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ron Shorts

ASKER

Thanks both!!!