PowerShell kullanarak SharePoint Yapılandırma Envanterini XML'e aktarma


Gereksinim: Web uygulamaları, içerik veritabanları vb. gibi farklı ortamlar arasında belirli SharePoint envanterlerini karşılaştırmamız gerekiyordu. Bu nedenle, SharePoint yapılandırmalarını bir XML dosyasına çıkarmamız ve dışa aktarmamız gerekiyordu.

Web Uygulamaları Listesini XML'e Aktarmak için PowerShell Komut Dosyası

PowerShell kullanarak SharePoint liste verilerini XML'e aktarın:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Create new XML File
[System.XML.XMLDocument]$XMLDocument=New-Object System.XML.XMLDocument

#Add XML Declaration
$Declaration = $XMLDocument.CreateXmlDeclaration("1.0","UTF-8",$null)
$XMLDocument.AppendChild($Declaration)

#Create Root Node
[System.XML.XMLElement]$XMLRoot=$XMLDocument.CreateElement("WebApplications")

#Get all web applications and loop through
$WebApps = Get-SPWebApplication
ForEach($webApp in $WebApps)
{
    $WebAppElement = $XMLDocument.CreateElement("WebApplication")
    $WebAppElement.SetAttribute("Name", $WebApp.DisplayName)
    $WebAppElement.SetAttribute("URL", $WebApp.URL)
    #Append the data to Root node
    $XMLRoot.AppendChild($WebAppElement)
}
# Append Root Node to XML
$XMLDocument.AppendChild($XMLRoot)

#Save File
$XMLDocument.Save("c:\WebApps.xml")

Komut dosyası çıktısı:

XML ile ilişkili Envanter Web Uygulamaları ve İçerik Veritabanları

Veritabanı bilgilerini ekleyelim:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Create new XML File
[System.XML.XMLDocument]$XMLDocument=New-Object System.XML.XMLDocument

#Add XML Declaration
$Declaration = $XMLDocument.CreateXmlDeclaration("1.0","UTF-8",$null)
$XMLDocument.AppendChild($Declaration)

#Create Root Node "WebApplications"
[System.XML.XMLElement]$WebAppRootElement=$XMLDocument.CreateElement("WebApplications")

#Get all web applications and loop through
$WebApps = Get-SPWebApplication
ForEach($webApp in $WebApps)
{
    $WebAppElement = $XMLDocument.CreateElement("WebApplication")
    $WebAppElement.SetAttribute("Name", $WebApp.DisplayName)
    $WebAppElement.SetAttribute("URL", $WebApp.URL)

    #Append the WebApplication data to "WebApplications" Node
    $WebAppRootElement.AppendChild($WebAppElement)

    #Database Element
    $DatabaseRootElement = $XMLDocument.CreateElement("Databases")

    $ContentDBs = $webApp.ContentDatabases
    ForEach($Database in $ContentDBs)
    {
        $DatabaseElement = $XMLDocument.CreateElement("Database") 
        $DatabaseElement.SetAttribute("Name", $Database.DisplayName)
        $DatabaseElement.SetAttribute("ID", $Database.ID)
           
        #Append the Database elements to "WebApplication" node
        $WebAppElement.AppendChild($DatabaseElement)
    }
}
# Append Root Node to XML
$XMLDocument.AppendChild($WebAppRootElement)

#Save File
$XMLDocument.Save("c:\WebApps-inventory.xml")

PowerShell'den SharePoint Hizmet Uygulamalarının XML'e Envanterine

SharePoint 2016 Hizmet Uygulamalarının Envanterini Çıkaralım:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Create new XML File
[System.XML.XMLDocument]$XMLDocument=New-Object System.XML.XMLDocument

#Add XML Declaration
$Declaration = $XMLDocument.CreateXmlDeclaration("1.0","UTF-8",$null)
$XMLDocument.AppendChild($Declaration)

#Create Root Node "ServiceApplications"
[System.XML.XMLElement]$ServiceAppRootElement=$XMLDocument.CreateElement("ServiceApplications")

#Get all Service applications and loop through
$ServiceApps = Get-SPServiceApplication
Foreach($ServiceApp in $ServiceApps)
{
    $ServiceAppElement = $XMLDocument.CreateElement("ServiceApplication")
    $ServiceAppElement.SetAttribute("TypeName",$ServiceApp.TypeName)
    $ServiceAppElement.SetAttribute("DisplayName", $ServiceApp.DisplayName)
    $ServiceAppElement.SetAttribute("Status", $ServiceApp.Status)    

    #Get the Account and Proxy Group of the Service App
    $ServiceAccountElement = $XMLDocument.CreateElement("ServiceAccount")
    $ServiceAccountElement.Set_InnerText($ServiceApp.ApplicationPool.ProcessAccountName)
    #Append to "ServiceApplication" node
    $ServiceAppElement.AppendChild($ServiceAccountElement)

    $ServiceAppProxyElement = $XMLDocument.CreateElement("ProxyGroup")
    $ServiceAppProxyElement.Set_InnerText($ServiceApp.ServiceApplicationProxyGroup.FriendlyName)
    #Append to "ServiceApplication" node
    $ServiceAppElement.AppendChild($ServiceAppProxyElement)    

    #Append the Service Application data to "ServiceApplications" Node
    $ServiceAppRootElement.AppendChild($ServiceAppElement)
}
# Append Root Node to XML
$XMLDocument.AppendChild($ServiceAppRootElement)

#Save File
$XMLDocument.Save("c:\ServiceAppsInventory.xml")

ve aşağıdaki çıktıyı üretir:

İlgili makaleler