码迷,mamicode.com
首页 > 其他好文 > 详细

SharePoint 2010: Export User Profile Properties to a Text File or Excel using PowerShell

时间:2014-07-17 21:37:20      阅读:454      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   os   

导出到txt

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")             
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles")             
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")            
            
# SharePoint site URL             
$site = new-object Microsoft.SharePoint.SPSite("http://contoso.com/");             
$ServiceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext($site);                
$ProfileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)            
$AllProfiles = $ProfileManager.GetEnumerator()            
$file = New-Object System.IO.StreamWriter "D:\UserProfiles.txt";            
$file.Writeline("CustomID|Accountname|PreferredName|UserName|FirstName|LastName|DeskPhoneNo|Department|Title|Manager|WorkEmail|Office|Classification|ServiceDate");            
foreach($profile in $AllProfiles)             
{            
    $CustomID = $profile["CustomID"].value            
    $AccountName = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value             
    $PreferredName = $profile["PreferredName"].value            
    $UserName = $profile["UserName"].value            
    $FirstName = $profile["FirstName"].value            
    $LastName = $profile["LastName"].value            
    $DeskPhoneNo = $profile["DeskPhoneNo"].value            
    $Department = $profile["Department"].value            
    $Title = $profile["Title"].value            
    $Manager = $profile["Manager"].value            
    $WorkEmail = $profile["WorkEmail"].value            
    $Office = $profile["Office"].value            
    $Classification = $profile["Classification"].value            
    $ServiceDate = $profile["ServiceDate"].value            
    $file.Writeline($CustomID+"|"+$AccountName+"|"+$PreferredName+"|"+$UserName+"|"+$FirstName+"|"+$LastName+"|"+$DeskPhoneNo+"|"+$Department+"|"+$Title+"|"+$Manager+"|"+$WorkEmail+"|"+$Office+"|"+$Classification+"|"+$ServiceDate);            
}            
$file.close();            
            
$site.Dispose()

导出到excel

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

导出乱码问题

Export-Csv $outputFile -NoTypeInformation -Encoding Unicode

SharePoint 2010: Export User Profile Properties to a Text File or Excel using PowerShell,布布扣,bubuko.com

SharePoint 2010: Export User Profile Properties to a Text File or Excel using PowerShell

标签:des   style   blog   http   color   os   

原文地址:http://www.cnblogs.com/jindahao/p/3851605.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!