【问题标题】:Get-SPContentDatabase export to CSV and include web application urlGet-SPContentDatabase 导出为 CSV 并包含 Web 应用程序 url
【发布时间】:2016-09-13 06:50:21
【问题描述】:

我正在尝试使用 powershell one liner 将我所有的 SharePoint 内容数据库的信息导出到一个 CSV 文件中,然后该文件可以用作安装脚本的输入。

如果我跑:

Get-SPContentDatabase | Select Name, DatabaseServer, MaximumSiteCount, WarningSiteCount | Export-CSV DatabaseExport.CSV

我获得了我需要的大部分信息,但我无法获得 Web 应用程序 url。 WebApplication 导出为“SPWebApplication Name=webappname”,我需要 url 或 ID。

我想我需要在一个脚本中提出它,这将添加循环并将 url 添加到导出的 CSV...但是将它放在一个衬里会很好。

【问题讨论】:

    标签: powershell sharepoint sharepoint-2010 sharepoint-2013 export-to-csv


    【解决方案1】:

    您可以使用计算属性(powershell 的一个非常酷的功能)!给你一行脚本;)

    Get-SPContentDatabase | select Name, Server, MaximumSiteCount, WarningSiteCount , @{Name="URL";Expression={$_.WebApplication.Url}} | Export-Csv TestDB.csv -NoTypeInformation
    

    【讨论】:

      【解决方案2】:

      好吧,万一没有人或你想出一个单一的解决方案,我将分享我的版本:

      $dbs = Get-SPContentDatabase
      $result = @();
      foreach($db in $dbs){
          $obj = New-Object PSObject
          $obj | Add-Member -Type NoteProperty -Name "URL" -Value $db.WebApplication.URL
          $obj | Add-Member -Type NoteProperty -Name "Name" -Value $db.Name
          $obj | Add-Member -Type NoteProperty -Name "DatabaseServer" -Value $db.Server
          $obj | Add-Member -Type NoteProperty -Name "MaximumSiteCount" -Value $db.MaximumSiteCount
          $obj | Add-Member -Type NoteProperty -Name "WarningSiteCount" -Value $db.WarningSiteCount
          $result += $obj
      }
      
      $result | Export-Csv .\DatabaseExport.csv -NoTypeInformation
      

      如果需要,只需添加/删除属性。查看this list 了解您可以使用的所有属性:)

      【讨论】:

      • 谢谢。这几乎就是我所拥有的。看起来我应该能够在一行 PowerShell 中做到这一点。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-21
      • 1970-01-01
      • 2020-12-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多