0

I am trying run below script on SP 2010 environment for getting list users on farm level. But i am getting error. Can someone please correct me.

Powershell script


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue  

Output Report File

$currentLocation = (Get-Location).Path $outputReport = $currentLocation + "\" + "SharePointUsers.csv"

Write CSV File Header

 

Array to hold user data

$UserDataCollection = @()  

Get All Web Applications and iterate through

$WebAppsColl = Get-SPWebApplication

   foreach($WebApp in $WebAppsColl) {     Write-host "Scanning Web Application:"$WebApp.Name     #Get All site collections and iterate through     $SitesColl = $WebApp.Sites          foreach ($Site in $SitesColl)     {         Write-host "Scanning Site Collection:"$Site.URL                        foreach ($web in $WebsColl)             {                 Write-host "Scanning Web:"$Web.URL                 #Get All Users of the Web                 $UsersColl = $web.AllUsers  #get all users programmatically                     #list all users                     foreach ($user in $UsersColl)                     {                            if($User.IsDomainGroup -eq $false)                             {                                 $UserData = New-Object PSObject                                                 $UserData | Add-Member -type NoteProperty -name "UserLogin" -value $user.UserLogin.ToString()                                 $UserData | Add-Member -type NoteProperty -name "DisplayName" -value $user.displayName.ToString()                                 $UserData | Add-Member -type NoteProperty -name "E-mailID" -value $user.Email.ToString()                                   $UserDataCollection += $UserData                             }                     }             $Web.dispose()             }          $site.dispose()         }     }        #Remove duplicates     $UserDataCollection = $UserDataCollection | sort-object -Property  {$_.UserLogin } -Unique       #Remove duplicates and export all users to excel     $UserDataCollection | Export-Csv -LiteralPath $OutputReport -NoTypeInformation                Write-host "Total Number of Unique Users found:"$UserDataCollection.Length

Error i am get as below:

Sort-Object : A parameter cannot be found that matches parameter name 'Propert  '. At C:\Users\sp_farm\Farmlevelusers.ps1:57 char:71 +     $UserDataCollection = $UserDataCollection | sort-object -Property  <<<< {$_.UserLogin } -Unique + CategoryInfo : InvalidArgument: (:) [Sort-Object], ParameterBin dingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Comm ands.SortObjectCommand

Export-Csv : A parameter cannot be found that matches parameter name 'LiteralP th'. At C:\Users\sp_farm\Farmlevelusers.ps1:60 char:50 +     $UserDataCollection | Export-Csv -LiteralPath <<<< $OutputReport -NoTyp Information + CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBind ingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Comm ands.ExportCsvCommand

Please correct me.

1 Answer 1

0

The script you provide doesn’t seem to be a complete version. The error message indicates the parameters and the cmdlets are not matching.

Here’s another sample script to get all users on farm level for your reference.

Get All Users In A SharePoint 2010/13/16 Farm Using PowerShell Script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.