?
Solved

Get user profiles from SharePoint 2010 and put in Excel

Posted on 2014-08-19
6
Medium Priority
?
699 Views
Last Modified: 2014-08-19
Trying to get a list of user profiles from SharePoint 2010.
Ive already tried script at https://onedrive.live.com/?cid=5593AB40F8C855AD&id=5593AB40F8C855AD%213364
and got errors, so I need a different Powershell script or other method to get all existing profiles, preferably into a CSV so I can put in Excel.
0
Comment
Question by:Montoya
  • 4
  • 2
6 Comments
 
LVL 8

Accepted Solution

by:
Jayaraja Jayaraman earned 2000 total points
ID: 40270270
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$siteUrl = "http://sp2010"
$outputFile = "C:\UserProfiles.csv"

$serviceContext = Get-SPServiceContext -Site $siteUrl
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext);
$profiles = $profileManager.GetEnumerator()

Write-Host "Exporting profiles"

$collection = @()
foreach ($profile in $profiles) {
 
  $profileData = "" | select "AccountName","FirstName", "LastName","PreferredName","WorkPhone"
   $profileData.AccountName = $profile["AccountName"].Value
   $profileData.FirstName = $profile["FirstName"].Value
   $profileData.LastName = $profile["LastName"].Value
   $profileData.PreferredName = $profile["PreferredName"].Value
   $profileData.WorkPhone = $profile["WorkPhone"].Value
   $collection += $profileData
}

$collection | Export-Csv $outputFile -NoTypeInformation
0
 
LVL 19

Author Comment

by:Montoya
ID: 40270287
is this a ps1 script?
0
 
LVL 19

Author Comment

by:Montoya
ID: 40270302
this script errors out for me..

PS C:\Powershell> .\allusers2
New-Object : Exception calling ".ctor" with "1" argument(s): "Object reference
not set to an instance of an object."
At C:\Powershell\allusers2.ps1:7 char:29
+ $profileManager = New-Object <<<<  Microsoft.Office.Server.UserProfiles.UserP
rofileManager($serviceContext);
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvoca
   tionException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.Power
   Shell.Commands.NewObjectCommand

You cannot call a method on a null-valued expression.
At C:\Powershell\allusers2.ps1:8 char:42
+ $profiles = $profileManager.GetEnumerator <<<< ()
    + CategoryInfo          : InvalidOperation: (GetEnumerator:String) [], Run
   timeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Exporting profiles
Cannot index into a null array.
At C:\Powershell\allusers2.ps1:16 char:40
+    $profileData.AccountName = $profile[ <<<< "AccountName"].Value
    + CategoryInfo          : InvalidOperation: (AccountName:String) [], Runti
   meException
    + FullyQualifiedErrorId : NullArray

Cannot index into a null array.
At C:\Powershell\allusers2.ps1:17 char:38
+    $profileData.FirstName = $profile[ <<<< "FirstName"].Value
    + CategoryInfo          : InvalidOperation: (FirstName:String) [], Runtime
   Exception
    + FullyQualifiedErrorId : NullArray

Cannot index into a null array.
At C:\Powershell\allusers2.ps1:18 char:37
+    $profileData.LastName = $profile[ <<<< "LastName"].Value
    + CategoryInfo          : InvalidOperation: (LastName:String) [], RuntimeE
   xception
    + FullyQualifiedErrorId : NullArray

Cannot index into a null array.
At C:\Powershell\allusers2.ps1:19 char:42
+    $profileData.PreferredName = $profile[ <<<< "PreferredName"].Value
    + CategoryInfo          : InvalidOperation: (PreferredName:String) [], Run
   timeException
    + FullyQualifiedErrorId : NullArray

Cannot index into a null array.
At C:\Powershell\allusers2.ps1:20 char:38
+    $profileData.WorkPhone = $profile[ <<<< "WorkPhone"].Value
    + CategoryInfo          : InvalidOperation: (WorkPhone:String) [], Runtime
   Exception
    + FullyQualifiedErrorId : NullArray

PS C:\Powershell>
0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
LVL 19

Author Comment

by:Montoya
ID: 40270305
I also need to get the user's Title, please.

Thank you for your efforts.
0
 
LVL 19

Author Comment

by:Montoya
ID: 40270359
Any suggestions, Layaraja?
0
 
LVL 8

Expert Comment

by:Jayaraja Jayaraman
ID: 40270400
yes this is a powershell script .
quick check on the script.....
1. did you run under admin account (farm admin)?
2.Did you change the site collection url ?
and for the ctor error refer here http://blogs.catapultsystems.com/rhutton/archive/2012/10/11/updating-a-user-profile-picture-using-powershell-exception-calling-quote-ctor-quote-with-quote-1-quote-argument.aspx

for title..change it to
  $profileData = "" | select "AccountName","FirstName", "LastName","PreferredName","WorkPhone","Title"
and add one more line
   $profileData.Title= $profile["Title"].Value
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

Lost Word File? Eagerly, need it back? Read ahead; this File Recovery guide is for you.
I came across an unsolved Outlook issue and here is my solution.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

850 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