Wednesday, May 15, 2024

Script to get specific list data from multiple sites in SharePoint 2013/2016

 Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue


# Import site URLs and titles from CSV file

$siteurls = Import-Csv -Path "D:\Sathyam\IPP\IPP_Subsites.csv"


# Array to hold all results from all sites

$AllListItemCollection = @()


# Iterate through each site in the CSV

foreach($webs in $siteurls) {

    $web = $null

    try {

        # Get the web object for the site

        $web = Get-SPWeb -Identity $webs.SiteURL  #Siteurl is the column name in the excel file. 

        $siteTitle = $webs.SiteTitle

        # Get the target list

        $list = $web.Lists["Listname"]

        Write-Host $web.Url

        

        # Loop through each item in the list

        $list.Items | foreach {

            $ExportItem = New-Object PSObject

            $ExportItem | Add-Member -MemberType NoteProperty -name "SiteURL" -value $web.Url

            $ExportItem | Add-Member -MemberType NoteProperty -name "Decision Type" -value $_["Milestone_x0020_Type1"]  # Milestone_x0020_Type1 is column internal Name. 

            $ExportItem | Add-Member -MemberType NoteProperty -name "Key Deliverable?" -value $_["Key_x0020_Milestone_x003F_"]

            $ExportItem | Add-Member -MemberType NoteProperty -name "Title" -value $_["Title"]

            $ExportItem | Add-Member -MemberType NoteProperty -Name "Item Status" -value $_["Item_x0020_Status"]

            $ExportItem | Add-Member -MemberType NoteProperty -name "Rejected" -value $_["Rejected"]

            $ExportItem | Add-Member -MemberType NoteProperty -name "Keyword(s)" -value $_["Keywords"]

            $ExportItem | Add-Member -MemberType NoteProperty -name "Created" -value $_["Created"]

            $ExportItem | Add-Member -MemberType NoteProperty -name "Created By" -value $_["Author"]

            $ExportItem | Add-Member -MemberType NoteProperty -name "Modified" -value $_["Modified"]

            $ExportItem | Add-Member -MemberType NoteProperty -name "Modified By" -value $_["Editor"]


            # Add the object to the all results array

            $AllListItemCollection += $ExportItem

        }

    } catch {

        Write-Host "Error accessing site or list: $($_.Exception.Message)" -ForegroundColor Red

    } finally {

        # Dispose of the web object if it was created

        if ($web) {

            $web.Dispose()

        }

    }

}


# Export the aggregated result array to a single CSV file

$AllListItemCollection | Export-CSV "D:\Sathyam\IPP\output\AllSitesOutput.csv" -NoTypeInformation


Thursday, May 9, 2024

PowerShell script to get InfoPath Lists reports from a Sharepoint 2013

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 

 

#Configuration parameters

#$WebAppURL="https://intranet.crescent.com"

$ReportOutput="D:\Sathyam\InfoPath-ListForms.csv"

#Array to Hold Result - PSObjects

$ResultColl = @()

 

 $webApps = Get-SPWebApplication

 foreach ($webApp in $webApps) {


#Get All Webs of the Web Application

$WebsColl = Get-SPWebApplication $WebApp | Get-SPSite -Limit All | Get-SPWeb -Limit All 

 

#Iterate through each web

Foreach($Web in $WebsColl)

 #Get All Lists with InfoPath List Forms in use

 Foreach ($List in $web.Lists | Where { $_.ContentTypes[0].ResourceFolder.Properties["_ipfs_infopathenabled"]})

    {

            Write-Host "Found an InfoPath Form at: $($Web.URL), $($List.Title)"

            $Result = new-object PSObject

            $Result | add-member -membertype NoteProperty -name "Site URL" -Value $web.Url

            $Result | add-member -membertype NoteProperty -name "List Name" -Value $List.Title

            $Result | add-member -membertype NoteProperty -name "List URL" -Value "$($Web.Url)/$($List.RootFolder.Url)"

            $Result | add-member -membertype NoteProperty -name "Template" -Value $list.ContentTypes[0].ResourceFolder.Properties["_ipfs_solutionName"]

            $ResultColl += $Result

    }

}

#Export Results to a CSV File

$ResultColl | Export-csv $ReportOutput -notypeinformation

Write-Host "InfoPath Lists Forms Report has been Generated!" -f Green

Sharepoint workflows report

Add-PSSnapin microsoft.sharepoint.powershell


Function global:Get-SPWebApplication($WebAppURL)

{

 return [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($WebAppURL)

}

 

#Function to Get the workflow inventory for the entire web application

function Get-WorkflowInventory([string] $WebAppURL)

{

    #Get the Web Application URL

    $WebApp = Get-SPWebApplication $WebAppURL 

  

    #Iterate through each site collection

    foreach ($Site in $WebApp.Sites)

          {                              

                #Loop through each site     

                foreach ($Web in $Site.AllWebs)

                   {

                    #Loop through each list

                    foreach ($List in $Web.Lists)

                      {

                         # Leave hidden Lists and Libraries

                         if($List.Hidden -eq $false)

                         {

                            foreach ($WorkflowAssociation in $List.WorkflowAssociations)

                            {

                                #Leave the "Previous Versions"

                                if($WorkflowAssociation.Name.Contains("Previous Version") -eq $false)

                                    {

                                       $data = @{

                                        "Site" = $Site.Rootweb.Title

                                        "Web" = $Web.Title

                                        "Web URL" = $Web.Url

                                        "List Name" = $List.Title

                                        "List URL" =  $Web.Url+"/"+$List.RootFolder.Url

                                        "Workflow Name" = $WorkflowAssociation.Name

                                        "Running Instances" = $WorkflowAssociation.RunningInstances

                                        }

                                         

                                        #Create an object

                                        New-Object PSObject -Property $data

                                    }

                              }

                          }                    

                    }

                     $Web.Dispose()                  

                }

                $Site.Dispose()                   

    }

 

#call the function

Get-WorkflowInventory "https://SPwebapplication.contoso.com/" | Export-Csv -NoTypeInformation -Path D:\Sathyam\SPWebappname_WorkflowInventory.csv

 

write-host "Workflows Inventory report has been generated successfully!"