Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

O365: Get-Content | Get-MsolUser Information

Posted on 2016-08-24
7
Medium Priority
?
581 Views
Last Modified: 2016-08-24
I am looking to run a PowerShell command to export specific data from my Office 365 Tenant...

Referencing 'O365Users.txt' contains a list of UPNs.

Get-Content C:\TEMP\O365Users.txt | Get-MsolUser -ALL | Select UserPrincipalName,DisplayName,Title,UsageLocation,Office,Department,IsLicensed,SignInName | Sort Title | Export-CSV C:\TEMP\Titles.csv

Error:
Get-MsolUser : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.

How could I pull this specific data? Thanks in advance.
0
Comment
Question by:Christian Hans
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 43

Expert Comment

by:Vasil Michev (MVP)
ID: 41768977
Is it a CSV file? If so, try the following:

Import-CSV C:\TEMP\O365Users.txt | % { Get-MsolUser -UserPrincipalName $_.UPN | Select UserPrincipalName,DisplayName,Title,UsageLocation,Office,Department,IsLicensed,SignInName | Sort Title } | Export-CSV C:\TEMP\Titles.csv

Open in new window

0
 

Author Comment

by:Christian Hans
ID: 41768988
The file I am pulling from is a TXT file, so even when I create a CSV to pull from I get the following:

Get-MsolUser : Cannot bind argument to parameter 'UserPrincipalName' because it is null.
0
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 41768991
Can't test it, but according to https://msdn.microsoft.com/en-us/library/azure/dn194133(v%3Dazure.98).aspx, the identifiers passed through the pipeline are only accepted by PropertyName.
So either pretend that your text file is a CSV by adding the header with the required property name:
Import-Csv C:\TEMP\O365Users.txt -Header UserPrincipalName | Get-MsolUser -ALL | Select UserPrincipalName,DisplayName,Title,UsageLocation,Office,Department,IsLicensed,SignInName | Sort Title | Export-CSV C:\TEMP\Titles.csv

Open in new window

Or use a ForEach and pass the loop variable to the UserPrincipalName argument
Get-Content C:\TEMP\O365Users.txt | % {Get-MsolUser -UserPrincipalName $_ | Select UserPrincipalName,DisplayName,Title,UsageLocation,Office,Department,IsLicensed,SignInName | Sort Title} | Export-CSV C:\TEMP\Titles.csv

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Christian Hans
ID: 41768995
Import-CSV C:\TEMP\O365Users.txt Results:

Import-CSV C:\TEMP\O365Users.txt | % { Get-MsolUser -UserPrincipalName $_.UPN | Select UserPrincipalName,DisplayName,Title,UsageLocation,Office,Department,IsLicensed,SignInName | Sort Title } | Export-CSV C:\TEMP\Titles.csv

Get-MsolUser : Cannot bind argument to parameter 'UserPrincipalName' because it is null.
At line:1 char:98
+ ... ng\O365Users.txt | % { Get-MsolUser -UserPrincipalName $_.UPN | Selec ...


------------------------------------------------------

Import-CSV C:\TEMP\O365Users.csv Results:

Import-CSV C:\TEMP\O365Users.csv | % { Get-MsolUser -UserPrincipalName $_.UPN | Select UserPrincipalName,DisplayName,Title,UsageLocation,Office,Department,IsLicensed,SignInName | Sort Title } | Export-CSV C:\TEMP\Titles.csv

Get-MsolUser : Cannot bind argument to parameter 'UserPrincipalName' because it is null.
At line:1 char:98
+ ... ng\O365Users.csv | % { Get-MsolUser -UserPrincipalName $_.UPN | Selec ...

------------------------------------------------------

Get-Content C:\TEMP\O365Users.txt Results:

Get-Content C:\TEMP\O365Users.txt | % { Get-MsolUser -UserPrincipalName $_.UPN | Select UserPrincipalName,DisplayName,Title,UsageLocation,Office,Department,IsLicensed,SignInName | Sort Title } | Export-CSV C:\TEMP\Titles.csv

Get-MsolUser : Cannot bind argument to parameter 'UserPrincipalName' because it is null.
At line:1 char:99
+ ... ng\O365Users.txt | % { Get-MsolUser -UserPrincipalName $_.UPN | Selec ...
0
 
LVL 43

Expert Comment

by:Vasil Michev (MVP)
ID: 41769010
Might be best if you simply give us example of the file :)
0
 
LVL 85

Expert Comment

by:oBdA
ID: 41769021
1. Import-CSV C:\TEMP\O365Users.txt
Like with my first example above (https:#a41768991 which would be the easiest to use, actually), you can import a plain text file (without headers) as csv if you pass the header list to Import-Csv; in your example above, that would be "UPN".
Import-CSV C:\TEMP\O365Users.txt -Header UPN | % { Get-MsolUser -UserPrincipalName $_.UPN ...

2. Import-CSV C:\TEMP\O365Users.csv
If you're importing from a csv and working with the ForEach cmdlet,, the csv needs a header line, and you need to pass the loop variable with the column name you used as the header line. In your second example above, that would be 'UPN':
... -UserPrincipalName $_.UPN ...
The csv file would need to look like that:
UPN
john.doe@domain.com

3. Get-Content C:\TEMP\O365Users.txt
If you're importing from a plain text file, and working with the ForEach cmdlet, you only need to pass the loop variable; the UPN property of a string will always be $Null:
... -UserPrincipalName $_ ...
0
 

Author Closing Comment

by:Christian Hans
ID: 41769096
That worked flawlessly... thank you oBdA

Get-Content C:\TEMP\O365Users.txt | % {Get-MsolUser -UserPrincipalName $_ | Select UserPrincipalName,DisplayName,Title,UsageLocation,Office,Department,IsLicensed,SignInName | Sort Title} | Export-CSV C:\TEMP\Titles.csv
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
Are you an Exchange administrator employed with an organization? And, have you encountered a corrupt Exchange database due to which you are not able to open its EDB file. This article will explain all the steps to repair corrupt Exchange database.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question