powershell 列出SharePoint场内使用的所有用户,并将其导出到.csv文件。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 列出SharePoint场内使用的所有用户,并将其导出到.csv文件。相关的知识,希望对你有一定的参考价值。

# ----------------------------------------------
# Author: Romain Blanchard
# Date: 02.03.2015
# Description: List all users used inside SharePoint farm, and export them to .csv file.
# ----------------------------------------------

# Initialize
$null = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

# Initialize log file
$date = Get-Date -Format yyyy-MM-d-HHmmss
$logfile = "RBLA_AllUsers_" + $date + ".txt"
Start-Transcript -Path $logfile -Force | Out-Null

# Initialize csv file
$csv = "RBLA_AllUsers_" + $date + ".csv"
Write-Output "Site Collection URl;User" | Out-File -FilePath $csv -Append

# Script
Write-Host "Exporting users." -NoNewLine
# Get all Web Application in the farm
$Farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
$websvcs = $Farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]}
$webapps = @()
foreach ($websvc in $websvcs)
{
    # Process all Web Application
    foreach ($WebApp in $websvc.WebApplications) 
    {
        # Process all Site Collection
        foreach ($SiteCollection in $WebApp.Sites)
        {
        Write-Host "." -NoNewLine   
            # Process all Site Groups
            foreach ($Group in $SiteCollection.RootWeb.SiteGroups)
            {
                # Process all users
                foreach ($User in $Group.Users)
                {
                    Write-Output "$($SiteCollection.Url);$($User.LoginName)" | Out-File -FilePath $csv -Append
                }
            }
        }
    }
}
Write-Host " done!" -ForegroundColor green

# Write log file
Stop-Transcript | Out-Null
$log = Get-Content $logfile
$log > $logfile.Replace('txt','log')
Remove-Item $logfile -Confirm:$false

以上是关于powershell 列出SharePoint场内使用的所有用户,并将其导出到.csv文件。的主要内容,如果未能解决你的问题,请参考以下文章

powershell 此PowerShell脚本列出了SharePoint列表中的所有字段内部名称。

10分钟精通SharePoint - SharePoint升级

powershell SharePoint Powershell在SharePoint模式下测试Analysis服务。这用于解决SharePoin中的Analysis服务问题

powershell SharePoint网站权限。正在进行的PowerShell项目,以分解sharepoint网站集和所有部分的所有权限

powershell Powershell用于将Powershell与SharePoint 2007一起使用

powershell SharePoint Powershell添加列表项