Get All AD users details using PowerShell and Export results as CSV
Today i have faced one scenario to export all the users details to Excel/CSV thru PowerShell.
Use the below script for the above scenaio
Use the below script for the above scenaio
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
[Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
$userProfiles = @()
$mysiteHostUrl = "http://SitteURL/my"
$mysite =
Get-SPSite $mysiteHostUrl
$context =
[Microsoft.Office.Server.ServerContext]::GetContext($mysite)
$upm =
New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$AllProfiles = $upm.GetEnumerator()
foreach($profile
in $AllProfiles)
{
write-host $profile["AccountName"].Value
$profileObject = New-Object PSObject
$profileObject | Add-Member -MemberType NoteProperty
-Name "Display
Name" -Value $profile.DisplayName
$profileObject | Add-Member -MemberType NoteProperty
-Name "Account
Name" -Value $profile["AccountName"].Value
$profileObject | Add-Member -MemberType NoteProperty
-Name "Email"
-Value $profile["WorkEmail"].Value
$userProfiles += $profileObject
#write-host
$profile.DisplayName + '-' + $profile["AccountName"].Value + '-' +
$profile["WorkEmail"].Value
}
$mysite.Dispose();
$userProfiles | Export-Csv -LiteralPath "c:\UsersInfo.csv"
-NoTypeInformation
Comments
Post a Comment