当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 PowerShell 获取 SharePoint 中的所有 Web 应用程序

作者:精品下载站 日期:2024-12-14 14:09:46 浏览:14 分类:玩电脑

使用 PowerShell 获取 SharePoint 中的所有 Web 应用程序


Web 应用程序是 SharePoint 中的顶级容器。我们在 SharePoint 中央管理中创建的每个 Web 应用程序都与 IIS 中的网站相关联。

如何获取 SharePoint 场中的所有 Web 应用程序?

在许多 SharePoint 环境中,都有用于不同功能的单独 Web 应用程序。例如,一个 Web 应用程序可能用于面向公众的网站,而另一个 Web 应用程序则用于内部网。还可能有针对不同部门或团队的其他 Web 应用程序。如果您想从 SharePoint 场获取所有这些 Web 应用程序,PowerShell 可以提供帮助。这篇博文将向您展示如何使用 PowerShell 获取 SharePoint 中的所有 Web 应用程序。

要获取 SharePoint 中所有可用 Web 应用程序的列表,请导航至:

  • SharePoint 2016 管理中心 >> 应用程序管理
  • 管理 Web 应用程序链接。

    [玩转系统] 使用 PowerShell 获取 SharePoint 中的所有 Web 应用程序

如何使用 PowerShell 获取所有 Web 应用程序 SharePoint

Get-SPWebApplication cmdlet 检索当前场中的所有 Web 应用程序。


Get-SPWebApplication

[玩转系统] 使用 PowerShell 获取 SharePoint 中的所有 Web 应用程序

上述 PowerShell cmdlet 提供所有 SharePoint Web 应用程序的 DisplayName 和 Url。要获取特定的 Web 应用程序,请使用:


Get-SPWebApplication https://yourwebappURL.com

您可以在 PowerShell 中迭代 Web 应用程序,如下所示:


#Get all web applications sharepoint using powershell
$WebAppColl = Get-SPWebApplication

#Iterate through each web application
Foreach ($WebApp in $WebAppColl)
{
    $Webapp.Url
}
#Or a one liner to loop through web applications
#Get-SPWebApplication | Select URL

这适用于 SharePoint 2013 和 2016 环境。该脚本要求您具有服务器场管理员权限才能运行它。

使用 PowerShell 获取 SharePoint 中的所有 Web 应用程序详细信息

让我们审核 SharePoint 中的所有 Web 应用程序以及其他详细信息(例如内容数据库的数量、身份验证类型、应用程序池名称等)并生成报告:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Parameters
$ReportOutput= "C:\WebApplications-Report.csv"
$DataCollection = @()

#Get all web applications sharepoint using powershell
$WebAppColl = Get-SPWebApplication
Foreach ($WebApp in $WebAppColl)
{
    #Determine the Authentication Type of the web application
    if ($WebApp.UseClaimsAuthentication) { $AuthticationTYpe = "Claims"} else {$AuthticationTYpe = "Classic" }

    #Get All Managed Paths of the web application
    $ManagedPaths =(Get-SPManagedPath -WebApplication $WebApp | Select -ExpandProperty Name) -join ","

    $WebAppData = new-object PSObject
    $WebAppData | add-member -membertype NoteProperty -name "Web Application Name" -Value $WebApp.Name
    $WebAppData | add-member -membertype NoteProperty -name "URL" -Value $WebApp.URL
    $WebAppData | add-member -membertype NoteProperty -name "No.of Content Databases" -Value $WebApp.ContentDatabases.Count 
    $WebAppData | add-member -membertype NoteProperty -name "Authentication Type" -Value $AuthticationTYpe
    $WebAppData | add-member -membertype NoteProperty -name "Application Pool" -Value $WebApp.ApplicationPool.DisplayName
    $WebAppData | add-member -membertype NoteProperty -name "Outgoing E-mail" -Value $WebApp.OutboundMailServiceInstance[0].Server.Address
    $WebAppData | add-member -membertype NoteProperty -name "Managed Paths" -Value $ManagedPaths

    $DataCollection += $WebAppData
}

#Export Results to a CSV File
$DataCollection | Export-csv $ReportOutput -notypeinformation
Write-Host "Web Application Audit Report has been Generated!" -f Green

此脚本生成 CSV 报告:

[玩转系统] 使用 PowerShell 获取 SharePoint 中的所有 Web 应用程序

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯