Solved

O365: Get-Content | Get-MsolUser Information

Posted on 2016-08-24
7
91 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 38

Expert Comment

by:Vasil Michev (MVP)
Comment Utility
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
Comment Utility
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 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:Christian Hans
Comment Utility
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 38

Expert Comment

by:Vasil Michev (MVP)
Comment Utility
Might be best if you simply give us example of the file :)
0
 
LVL 82

Expert Comment

by:oBdA
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
If you don't know how to downgrade, my instructions below should be helpful.
In this video we show how to create an email address policy in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Mail Flow…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now