Get user profiles from SharePoint 2010 and put in Excel

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.
LVL 19
MontoyaProcess Improvement MgrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jayaraja JayaramanSharepoint Architect ConsultantCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MontoyaProcess Improvement MgrAuthor Commented:
is this a ps1 script?
0
MontoyaProcess Improvement MgrAuthor Commented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

MontoyaProcess Improvement MgrAuthor Commented:
I also need to get the user's Title, please.

Thank you for your efforts.
0
MontoyaProcess Improvement MgrAuthor Commented:
Any suggestions, Layaraja?
0
Jayaraja JayaramanSharepoint Architect ConsultantCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SharePoint

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.