Tuesday, November 26, 2024

Power shell Script to get all lists and library columns and it's type to export into CSV from a Sharepoint 2013/2016 site collection and its subsites.

 


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue


# Configuration Parameters

$SiteURL = "https://intranet.crescent.com/sites/test"

$CSVPath = "D:\AllFields.csv"


# Get the Web

$Web = Get-SPWeb $SiteURL


# Create a DataTable to store the fields information

$DataTable = New-Object System.Data.DataTable

$DataTable.Columns.Add("ListTitle") | Out-Null

$DataTable.Columns.Add("FieldTitle") | Out-Null

$DataTable.Columns.Add("InternalName") | Out-Null

$DataTable.Columns.Add("FieldType") | Out-Null

$DataTable.Columns.Add("IsHidden") | Out-Null


# Iterate through each list and library

foreach ($List in $Web.Lists) {

    foreach ($Field in $List.Fields) {

        $Row = $DataTable.NewRow()

        $Row["ListTitle"] = $List.Title

        $Row["FieldTitle"] = $Field.Title

        $Row["InternalName"] = $Field.InternalName

        $Row["FieldType"] = $Field.TypeDisplayName

        $Row["IsHidden"] = $Field.Hidden

        $DataTable.Rows.Add($Row)

    }

}


# Export the DataTable to a CSV file

$DataTable | Export-Csv -Path $CSVPath -NoTypeInformation


# Dispose of the web object

$Web.Dispose()


Write-Host "All fields exported successfully to $CSVPath"


Power shell Script to get all lists and library columns and its type to export in to CSV from a Sharepoint 2013/2016 site.

 This script includes additional columns for the field type and whether the field is hidden. It ensures that all fields, including hidden and system fields, are collected and exported to the CSV file.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue


# Configuration Parameters

$SiteURL = "https://intranet.crescent.com/sites/test/"

$CSVPath = "D:\AllFields.csv"


# Get the Web

$Web = Get-SPWeb $SiteURL


# Create a DataTable to store the fields information

$DataTable = New-Object System.Data.DataTable

$DataTable.Columns.Add("ListTitle") | Out-Null

$DataTable.Columns.Add("FieldTitle") | Out-Null

$DataTable.Columns.Add("InternalName") | Out-Null

$DataTable.Columns.Add("FieldType") | Out-Null

$DataTable.Columns.Add("IsHidden") | Out-Null


# Iterate through each list and library

foreach ($List in $Web.Lists) {

    foreach ($Field in $List.Fields) {

        $Row = $DataTable.NewRow()

        $Row["ListTitle"] = $List.Title

        $Row["FieldTitle"] = $Field.Title

        $Row["InternalName"] = $Field.InternalName

        $Row["FieldType"] = $Field.TypeDisplayName

        $Row["IsHidden"] = $Field.Hidden

        $DataTable.Rows.Add($Row)

    }

}


# Export the DataTable to a CSV file

$DataTable | Export-Csv -Path $CSVPath -NoTypeInformation


# Dispose of the web object

$Web.Dispose()


Write-Host "All fields exported successfully to $CSVPath"


Thursday, October 17, 2024

"Access Denied" to Access Requests list or "Request approval failed" when you process a pending request

 

"Access Denied" to Access Requests list or "Request approval failed" when you process a pending request

Problem

You have a Microsoft SharePoint Online site on which the Allow access requests setting is enabled.

When users who have Full Control permissions to the site clicks Access requests and invitations in Site Settings, they receive the following error message:

Access Denied.

Also, when users browse to the Access Requests list and then click Approve or Decline for a pending request, they receive the following error message:

Sending approval
Request approval failed

Solution

To resolve this issue, users must be either site collection administrators or be members of the Owners group for the site. The Owners group must also have permissions to access the Access Requests list. Use the following solutions as appropriate for your specific configuration.

Site collection administrator

If an affected user should be a site collection administrator, go to the following Microsoft website for more information about how to manage administrators for your sites:

Manage site collection administrators

Add the user to the Owners group for the site

If the user should be a site owner, you must add the user to the Owners group for the site. To do this, follow these steps:

  1. As a user who can change site permissions, browse to the affected site or site collection. Click the gear icon for the Settings menu, and then click Site settings.

  2. Click Site permissions.

  3. Click the Owners group for the site.

  4. Click New.

  5. In the Share dialog box, enter the user account of the user who you want to add to the group. Then, click Share.

  6. Test to verify that the user can now access the list and approve or decline requests.

Make sure that the Owners group has permissions to the Access Requests list

If the Owners group is changed or was removed from the Access requests list, you must add the Owners group permissions for the list. You must also make sure that the affected user is included in the Owners list. To do this, follow these steps:

  1. As a user who has the Manage Permissions Permission Level on the affected site and who also has access to the Access Requests list (for example, a Site Collection administrator), browse to the Access Requests list in Internet Explorer.

  2. Press F12 to open the F12 Developer Tools window.

  3. Press Ctrl + F5 to refresh the page.

  4. Click the Debugger tab.

    Screenshot of the Debugger tab of F12 Developer Tools window.

  5. In the search box on the right hand side of the page, type pagelistid:, and then press Enter.

    Screenshot of the search box when you type PageListId.

  6. Copy the GUID that follows the pageListId located in the listedit.aspx page. The GUID will be between an opening brace ( { ) character and a closing brace ( } ) character as follows:

    Screenshot of an example of GUID that follows the pageListId.

  7. In the browser address bar, enter https://contoso.sharepoint.com>/_layouts/15/ListEdit.aspx?List=<{GUID}>.

    Example: https://contoso.sharepoint.com/_layouts/15/listedit.aspx?List=d078a4df-3c52-4b23-8c28-e9561a243f0c

     Note

    In this address, represents the URL for the site collection in which you want to change the access requests (for example, https://contoso.sharepoint.com). And <{GUID}> represents the GUID that you copied in step 6.

  8. On the Settings page, click Permissions for this list.

  9. Make sure that the Owners group for the site is included in the list of permissions for the Access Requests list. If the Owners group for the site collection does not exist, click Grant Permissions, enter the name of the Owners group for the site in the Share dialog box, and then click Share.

  10. Follow the steps in the "Add the user to the Owners group for the site" section to make sure that the user is included in the Owners group.

More information

This issue occurs because only site collection administrators or users who are members of the Owners group for the site collection have permission to approve or decline pending requests in the Access Requests list. For situations in which users are members of the Owners group for the site, the Owners group must also have Full Control permissions to be able to access the Access Requests list.

For more information about how to set up and manage access requests, go to Set up and manage access requests.

For more information about how to use the F12 developer tools, go to Using the F12 developer tools.

Ref link: Request approval failed when you process a pending request - SharePoint | Microsoft Learn

Wednesday, August 7, 2024

Site Analytics reports are empty after migrations.

 

Post Migrations popularity trends not pulling usage report's data. All the data showing 0's.

Issue : Usage report is showing up 0’s even though there are actual hits on the sites. Screenshot mentioned below.
 
Root Cause:
Verified and found that below two timer services ‘Last run time’ is showing up as N/A, due to which we are not getting the data to the Usage reports.
Analytics Timer Job for Search Service Application STG_Service_Search 
Usage Analytics Timer Job for Search Application STG_Service_Search
 
All the remaining settings are fine.

 
Resolution Steps:
 
1.Delete old corrupted below timer jobs :
 
Analytics Timer Job for Search Service Application STG__Service_Search 
Usage Analytics Timer Job for Search Application STG_Service_Search 
 
$tj1= Get-SPTimerJob -Type Microsoft.Office.Server.Search.Analytics.AnalyticsJobDefinition
$tj1.delete()
 
$tj2= Get-SPTimerJob -Type Microsoft.Office.Server.Search.Analytics.UsageAnalyticsJobDefinition
$tj2.delete()
 
 
2. Recreate both deleted timer jobs again 
 
$ssa = Get-SPEnterpriseSearchServiceApplication
$assembly = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.Search")
$bindingflags = [System.Reflection.BindingFlags]::NonPublic, [System.Reflection.BindingFlags]::Static
======================
$jobtypes = @("Microsoft.Office.Server.Search.Analytics.UsageAnalyticsJobDefinition","Microsoft.Office.Server.Search.Analytics.AnalyticsJobDefinition")
# Register analytics timer jobs
foreach ($jobtype in $jobtypes)
{
$type = $assembly.GetType($jobtype)
$registerJob = $type.GetMethod("RegisterJob", $bindingflags)
$registerJob.Invoke($type, $ssa)
}
 
 
3. Check running schedule details of both new timer jobs:
 
$tj1= Get-SPTimerJob -Type Microsoft.Office.Server.Search.Analytics.AnalyticsJobDefinition
$tj2= Get-SPTimerJob -Type Microsoft.Office.Server.Search.Analytics.UsageAnalyticsJobDefinition
 
Its will show garbage values.
 
 
 
4. Run it again with below commands 
 
$tj1= Get-SPTimerJob -Type Microsoft.Office.Server.Search.Analytics.AnalyticsJobDefinition
$tj1.RunNow()
--------------------------------------
$tj2= Get-SPTimerJob -Type Microsoft.Office.Server.Search.Analytics.UsageAnalyticsJobDefinition
$tj2.RunNow()
 
 
 
5. Now check new corrected running schedule:
$tj1= Get-SPTimerJob -Type Microsoft.Office.Server.Search.Analytics.AnalyticsJobDefinition
$tj2= Get-SPTimerJob -Type Microsoft.Office.Server.Search.Analytics.UsageAnalyticsJobDefinition
 
 
 
Validate the existing Existing Settings of Usage & Health Service application
 
After 24hours reports will be generated

Monday, July 22, 2024

Script to export the running workflow instances into an Excel file

# Load SharePoint snap-in if not already loaded

if ((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null) {

    Add-PSSnapin Microsoft.SharePoint.PowerShell

}


# Define the site URL, list name, and item ID

$siteUrl = "http://cssvc.corning.com/nafta/otc"

$listName = "OrderRelease"

$itemId = 55695  # Specify the ID of the item whose workflows you want to cancel


# Get the site, web, and list objects

#$site = Get-SPweb $siteUrl

$web = Get-SPweb $siteUrl

$list = $web.Lists[$listName]


# Get the list item

$item = $list.GetItemById($itemId)


# Get the workflow manager

$workflowManager = $web.Site.WorkflowManager


# Get all running workflows for the list item

$workflows = $workflowManager.GetItemActiveWorkflows($item)


# Cancel running workflows

foreach ($workflow in $workflows) {

    if ($workflow.InternalState -eq [Microsoft.SharePoint.Workflow.SPWorkflowState]::Running) {

        Write-Host "Cancelling workflow instance ID: $($workflow.InstanceId) for item ID: $itemId"

        #$workflowManager.RemoveWorkflow($workflow)

    }

}


# Clean up

$web.Dispose()

#$site.Dispose()


Write-Host "All running workflows for item ID $itemId have been cancelled."


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