PowerShell to Get All Files of Particular Type from a SharePoint Web Application

In a Branding revamp project, After updating new logo on the SharePoint CSS Files, Found there are lot of InfoPath forms out there with old logo. So had to figure out all deployed InfoPath XSN Templates!

PowerShell Script to Find all XSN Files:
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null
#For SharePoint 2007
function global:Get-SPSite($url){
    return new-Object Microsoft.SharePoint.SPSite($url)

#Function to Scan XSN Files
Function GetXSNFiles($Folder)
    foreach ($File in $Folder.Files | Where-Object {$_.Name -match ".xsn"} )
     #Write data to CSV File
     "$($Folder.ParentWeb.Site.RootWeb.Title)" +"`t"+ "$($Folder.ParentWeb.Title)" +"`t" + "$($Folder.ParentWeb.URL+"/")$($File.URL)" +"`t" + "$($File.TimeLastModified)" >> XSNTemplates.csv

    #Iterate through all subfolders
    foreach ($SubFolder in $Folder.SubFolders)
        #Call the function recursively
        GetXSNFiles $SubFolder
#Write the CSV header
"Site Collection `t Site `t Form Template `t Last Modified" > XSNTemplates.csv

#Get the web application
#Write-Host "Enter the Web Application URL:"
$WebAppURL= "http://sharepoint.crescent.com"   #$WebAppURL= Read-Host
$SiteColletion = Get-SPSite($WebAppURL)
$WebApp = $SiteColletion.WebApplication
#Loop through all site collections of the web app
    foreach ($site in $WebApp.Sites)
       #Get the collection of webs
       foreach($web in $site.AllWebs)
              write-host "scanning site" $web.title "@" $web.URL
              #Call the function to Get XSN Files
         #Dispose web object
        #Dispose site object
Write-host  "Report Generated: XSNTemplates.csv" -foregroundcolor green

Script will search each and every list and library for specific file type and log that information to a Tab Separated text file.

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.