SharePoint 2010: Export User Profile Properties to a Text File or Excel using PowerShell
2014-07-17 17:29
549 查看
导出到txt
导出到excel
导出乱码问题
[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
相关文章推荐
- Export large data from GridView to Excel file using C#
- How to export Gobla Address List (GAL) into an Excel file for Outlook 2010
- using vb.net export a datatable to Excel and save as file
- SQLite Tutorial 4 : How to export SQLite file into CSV or Excel file
- Upload Data from Excel File in ABAP using TEXT_CONVERT_XLS_TO_SAP
- SharePoint 2010 Server Error: The URL "XXX" is invalid, it may refer to a nonexistent file or ...
- 使用PowerShell更新SharePoint 2010 UserProfile Service的Property value
- ASP.NET datagrid直接导出为Excel Export to Excel from DataGrid (Using an Microsoft Access database)
- How to add, modify, or delete registry subkeys and values by using a registration entries (.reg) file
- 解决SharePoint 2010 User Profile Synchronization 的Timeout问题
- SharePoint 2010 SP1后出现User Profile Service Application意外错误的解决办法
- How to write an application that supports the Fast User Switching feature by using Visual Basic .NET or Visual Basic
- Openvms-C-Sourcecode- How to Find which Processes are using a specific pagefile or swapfile
- export excel file with using data table
- Import/Export Excel (.Xlsx) or (.Xls) File into SQL Server
- SharePoint 2010 “The specified user or domain group was not found”(转载)
- Export Internal Table to Excel using OLE
- [SharePoint 2010] 代码添加或管理User Profile Service-User Properties
- Using Servlet to Export File
- SaveTextFile - Save or append text to a file