I want to retrieve all the user email id, display name, user name & Title from user information list using power shell
1 Answer
You can use the below PowerShell script:
function ExtractSPuserInformationListToCSV()
{
param
(
[Parameter(Mandatory=$true)] [string] $SiteURL
)
$web = Get-SPWeb $SiteURL
$list = $web.Lists["User Information List"]
$spQuery = New-Object Microsoft.SharePoint.SPQuery
$CamlQueryString = '<Query><OrderBy><FieldRef Name="Title" Ascending="True" /></OrderBy></Query>'
$spQuery.Query = $CamlQueryString
$userInformationListItemsColls = $list.GetItems($spQuery)
foreach($oneUserInInformationList in $userInformationListItemsColls)
{
Write-Host $oneUserInInformationList.Title
$userData = Get-SPUser -Web $web.URL -Identity $oneUserInInformationList["ows_Name"]
$UserInformationlistItemData = @{
"Display Name" = $userData.DisplayName
"User Login" = $userData.UserLogin
"Email" = $userData.Email
"Name" = $userData.Name
}
New-Object PSObject -Property $UserInformationlistItemData
}
$web.Dispose();
return $UserInformationlistItemData
}
#Call the function like below
ExtractSPuserInformationListToCSV "YourSiteURL" | Export-Csv -NoTypeInformation -Path "Your CSV Path";
-
Hi - if it has helped you, could you please [Upvote(^)] and mark as answered.– SP 2022Commented Jun 19, 2020 at 0:34