Solved

O365: Get-Content | Get-MsolUser Information

Posted on 2016-08-24
7
261 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
  • 3
  • 2
  • 2
7 Comments
 
LVL 40

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 84

Accepted Solution

by:
oBdA earned 500 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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 40

Expert Comment

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

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Read this checklist to learn more about the 15 things you should never include in an email signature.
This article explains how to install and use the NTBackup utility that comes with Windows Server.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

821 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