Author Posts

February 23, 2017 at 10:23 am

Hi,

Struggling to get this right. Still a beginner 🙂

Scenario. We have different customer with different login.

Looking to create an PS script to put all the information into one or two csv.
How can i loop using an text file with the company names ?
what is the best way to "merge" csv files ?

#Read-Host "Enter Password" -AsSecureString | ConvertFrom-SecureString | Out-File "C:\password\password-$customer.txt"
## Customername
$customer = "company"
##Username login to portal.office.com
$User = "login name"
##Password files. Planning on going through all different customer to get them encrypted
$pass = "C:\password\password-$customer.txt"
## Passing credentials and password to O365
$cred=New-Object -TypeName System.Management.Automation.PSCredential `
-ArgumentList $User, (Get-Content $pass | ConvertTo-SecureString)
##Import module
import-module msonline
##Connecting to the service with credentials
Connect-MsolService -Credential $cred
##Definer where to save csv
$savetocsv = "C:\report\user-$customer.csv"
$savetocsv2 = "c:\report\licens-$customer.csv"
##Getting the information based on user
Get-MsolUser -all | select userprincipalname,islicensed,{$_.Licenses.accountskuid} |
Add-Member -MemberType NoteProperty -Name Company -Value "$customer" -PassThru |
export-csv $savetocsv -NoTypeInformation
##Getting the information based on licenses information
Get-MsolAccountSku | select accountskuid,activeunits,consumedunits |
Add-Member -MemberType NoteProperty -Name Company -Value "$customer" -PassThru |
export-csv $savetocsv2 -NoTypeInformation

February 23, 2017 at 2:23 pm

What is your goal? Are you creating a report? The AccountSku information is a key more than association with each user, your data would look like this:

UserPrincipalName : rob@email.com
IsLicensed        : yes
AccountSkuID      : f763d573-a4c3-4164-a20f-e5f67fba7020
ActiveUnits       : 3500
ConsumedUnits     : 3456

The above doesn't make sense to me, but it's certainly possible to dump data like this to a CSV. It would just help to understand what your end result would look like.

February 23, 2017 at 2:40 pm

Check out the azureAD preview, it's much simpler to get license information than the msol cmdlets.


PS H:\> (Get-AzureADUser -ObjectId me@somewhere.com).assignedplans

AssignedTimestamp     CapabilityStatus Service                       ServicePlanId
-----------------     ---------------- -------                       -------------
9/27/2016 3:30:05 PM  Enabled          YammerEnterprise              7547a3fe-08ee-4ccb-b430-5077c5041653
9/27/2016 3:30:04 PM  Enabled          MicrosoftCommunicationsOnline 0feaeb32-d00e-4d66-bd5a-43b5b83db82c
2/12/2016 8:14:00 PM  Enabled          MicrosoftOffice               f85945f4-7a55-4009-bc39-6a5f14a8eac1
10/27/2015 6:23:02 PM Enabled          exchange                      8c3069c0-ccdb-44be-ab77-986203a67df2
9/14/2015 2:08:22 PM  Enabled          SharePoint                    153f85dd-d912-4762-af6c-d6e0fb4f6692
9/14/2015 2:08:22 PM  Enabled          SharePoint                    8f9f0f3b-ca90-406c-a842-95579171f8ec
6/3/2015 7:41:08 PM   Enabled          AzureAnalysis                 2049e525-b859-401b-b2a0-e0a31c4b1fe4
5/12/2015 4:59:59 PM  Enabled          MicrosoftCommunicationsOnline 607f722d-4041-4a85-af8b-05bfa6fba209
2/9/2015 2:30:08 PM   Enabled          RMSOnline                     6a76346d-5d6e-4051-9fe3-ed3f312b5597
11/20/2014 9:12:02 PM Enabled          MicrosoftOffice               de9234ff-6483-44d9-b15e-dca72fdd27af


April 26, 2017 at 2:55 pm

Hi,

I have a script in place that adds 0365 Licenses based on a user's membership in an Active Directory Group. This portion on the script works. I'm looking for a method to remove the license if a user is not a member of an Active Directory Group.

Thanks,

Kevin C.