What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

For SharePoint Online, PnP PowerShell is usually the most practical starting point for finding files, inspecting modern pages, and making common page or web-part changes. Use Microsoft Graph PowerShell when its documented page and web-part API covers the task or when you need a governed app-based integration. For SharePoint Server, use the server’s native SharePoint PowerShell tools. These are separate toolsets, not interchangeable ways to run the same commands.

Choose the right PowerShell tool

“SharePoint information” can mean three different things: files and metadata in document libraries; modern pages, usually stored as .aspx files in the Site Pages library; and web-part instances arranged on a page canvas. A modern page is not the same as a classic Web Part Page, so a command that works for one page model may not work for the other.

Task Good starting point Why
SharePoint Online files, lists, libraries, and common modern-page tasks PnP PowerShell SharePoint-focused cmdlets provide a convenient operator workflow.
Page and web-part operations supported by Graph, especially app-based integrations Microsoft Graph PowerShell Uses Graph’s permission and resource model, but only exposes a subset of page-editing capabilities.
SharePoint Server farm administration SharePoint Server Management Shell Designed for the server environment and its administrative object model.
SharePoint Online tenant administration SharePoint Online Management Shell Useful for tenant administration, not a substitute for all file and page content operations.

PnP PowerShell is an open-source community project, not a Microsoft product with a Microsoft support SLA, even though Microsoft Learn documents it among SharePoint PowerShell resources. Review the SharePoint PowerShell overview and PnP’s support and page-layout notes before standardizing a production workflow. PowerShell also does not replace SharePoint Framework (SPFx) development: creating and deploying a custom web part is separate from placing an already-deployed part on a page.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Prerequisites and safe setup

  • A SharePoint Online site URL, or the correct SharePoint Server environment.
  • An account or application with permissions for the particular site, library, page, and operation. Browser access alone does not guarantee API access.
  • PowerShell 7 is a useful cross-platform choice; check the current module requirements and cmdlet syntax for your installed version.
  • A non-production site or copied page for testing, especially before changing page layout or web parts.
  • A backup or export of page state before destructive changes. Confirm draft, checkout, and approval behavior in the target library.

Install PnP PowerShell for the current user:

Install-Module PnP.PowerShell -Scope CurrentUser

For interactive SharePoint Online work, connect with an MFA-compatible sign-in:

$siteUrl = "https://contoso.sharepoint.com/sites/Marketing"
Connect-PnPOnline -Url $siteUrl -Interactive

Your tenant may require approval for the PnP Management Shell application. A successful sign-in does not prove you can read or edit every resource. For unattended jobs, use an organization-approved Entra ID application and certificate-based authentication rather than storing a user password in a script.

To use Graph, install the required Microsoft Graph PowerShell module and request scopes appropriate to the operation. For example, a read scenario may start with:

Connect-MgGraph -Scopes "Sites.Read.All"

A write scenario may require a broader permission, such as Sites.ReadWrite.All, and administrator consent. These scopes are examples, not guarantees that every operation will work: check the permission table for the specific API and distinguish delegated access (acting as a signed-in user) from application access (an app identity).

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Inventory files in a document library

Files and folders are represented as list items. This example retrieves selected fields in pages and exports a useful inventory:

$libraryName = "Documents"

Get-PnPListItem -List $libraryName -PageSize 500 `
    -Fields "FileLeafRef", "FileRef", "FSObjType", "File_x0020_Size", "Modified", "Editor" |
    ForEach-Object {
        [pscustomobject]@{
            Name       = $_["FileLeafRef"]
            Url        = $_["FileRef"]
            IsFolder   = ([int]$_.FieldValues.FSObjType -eq 1)
            Size       = $_["File_x0020_Size"]
            Modified   = $_["Modified"]
            ModifiedBy = $_["Editor"].LookupValue
        }
    } |
    Export-Csv ".sharepoint-files.csv" -NoTypeInformation

Field names are not universal. A custom library may use different internal names, and a size field may be absent or unpopulated. Inspect the list’s fields if a value is blank. Narrow field selection and -PageSize are safer than assuming a single request returns a large library.

To report only files and include creator and modifier details:

$items = Get-PnPListItem -List "Documents" -PageSize 500 `
    -Fields "FileLeafRef", "FileRef", "FSObjType", "Modified", "Created", "Author", "Editor"

$items |
    Where-Object { $_["FSObjType"] -eq 0 } |
    Select-Object `
        @{Name="Name"; Expression={ $_["FileLeafRef"] }},
        @{Name="Url"; Expression={ $_["FileRef"] }},
        @{Name="Created"; Expression={ $_["Created"] }},
        @{Name="Modified"; Expression={ $_["Modified"] }},
        @{Name="CreatedBy"; Expression={ $_["Author"].LookupValue }},
        @{Name="ModifiedBy"; Expression={ $_["Editor"].LookupValue }}

Other useful reporting targets include extension, content type, checkout state, approval status, version count, retention or sensitivity labels where available, and folder location. Permissions and sharing links usually need separate permission-focused queries; do not assume the basic list-item fields include them.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read metadata or download a known file

Use -AsListItem when you want the file’s list-item metadata:

$fileUrl = "/sites/Marketing/Shared Documents/Briefing.docx"
$fileItem = Get-PnPFile -Url $fileUrl -AsListItem
$fileItem.FieldValues

Use -AsFile to retrieve the binary:

Get-PnPFile -Url $fileUrl -Path ".downloads" `
    -FileName "Briefing.docx" -AsFile -Force

For a folder’s immediate contents, you can use:

Get-PnPFolderItem -FolderSiteRelativeUrl "Shared Documents" -ItemType File

Do not assume this is a recursive inventory of a large library. For broad reporting, query list items with paging or implement controlled folder traversal.

Use the right URL form

  • Tenant URL: the SharePoint Online host, such as https://contoso.sharepoint.com.
  • Site URL: the site collection or web you connect to, such as https://contoso.sharepoint.com/sites/Marketing.
  • Server-relative URL: begins with a slash and includes the site path, such as /sites/Marketing/Shared Documents/Briefing.docx.
  • Site-relative URL: interpreted relative to the connected site, often used for folder paths.

A browser address may contain encoded characters or extra view parameters. Copy the underlying file or page path and use the URL form expected by the cmdlet; “not found” often means the resource path was supplied in the wrong form.

Find and inspect modern pages

List items in Site Pages provide a useful page inventory:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Get-PnPListItem -List "Site Pages" -PageSize 200 `
    -Fields "FileLeafRef", "FileRef", "Title", "Modified", "PromotedState", "_UIVersionString" |
    Select-Object `
        @{Name="PageName"; Expression={ $_["FileLeafRef"] }},
        @{Name="Url"; Expression={ $_["FileRef"] }},
        @{Name="Title"; Expression={ $_["Title"] }},
        @{Name="Modified"; Expression={ $_["Modified"] }},
        @{Name="PromotedState"; Expression={ $_["PromotedState"] }},
        @{Name="Version"; Expression={ $_["_UIVersionString"] }}

To retrieve a modern page object by its file name:

$page = Get-PnPPage -Identity "Home.aspx"
$page

Accepted identity formats can vary by cmdlet version. If the command cannot resolve the page, confirm that you connected to the correct site and use the page’s actual name or supported path format in the installed module’s help.

Inspect page components and web parts

Modern pages store content on a client-side canvas. Retrieve the components and inspect their raw properties before writing code that depends on them:

$components = Get-PnPPageComponent -Page "Home.aspx"
$components | Format-List *

A compact view may help identify component IDs and positions, but properties vary by module version and component type:

Get-PnPPageComponent -Page "Home.aspx" |
    Select-Object Id, WebPartId, InstanceId, Section, Column, Order,
        @{Name="ComponentType"; Expression={ $_.GetType().Name }}

Not every web part exposes complete configuration through one stable, editable property. Standard parts, text parts, custom SPFx parts, and embedded content can behave differently. Export what you can inspect before making changes:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
$page = Get-PnPPage -Identity "Home.aspx"
$components = Get-PnPPageComponent -Page $page
$components | Export-Clixml ".Home-components-before.xml"

Add common web parts with PnP PowerShell

Add a text part to section 1, column 1:

Add-PnPPageTextPart -Page "Home.aspx" `
    -Text "<p>Updated by PowerShell.</p>" `
    -Section 1 -Column 1

SharePoint may normalize or encode the supplied HTML. Test formatting, links, images, and embedded markup on a disposable page before applying it to a live page.

A standard List web part can be configured to show a document library, for example:

Add-PnPPageWebPart -Page "Home.aspx" `
    -DefaultWebPartType "List" `
    -Section 1 -Column 1 `
    -WebPartProperties @{
        isDocumentLibrary  = "true"
        webRelativeListUrl = "/Shared Documents"
    }

-DefaultWebPartType is for supported/default types. A custom SPFx part may need a component identifier and exact properties, and the package must already be deployed and available to the site. Deployment and permission approval are separate from adding a page instance. Microsoft’s modern-page PnP example demonstrates common page and web-part operations, but verify syntax and behavior against your installed module.

Some page operations are sensitive to checkout, library approval, and publishing configuration. A successful command is not proof that the change is live to readers.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set a modern page layout

Set-PnPPage -Identity "Dashboard.aspx" `
    -LayoutType SingleWebPartAppPage

SingleWebPartAppPage is a locked layout intended to host one web part or application. Changing layout can alter the page experience; test on a copy and verify that the target page type and module support the operation. See Microsoft’s single-part app page documentation.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When Microsoft Graph is a better fit

Graph represents modern pages and web parts as resources and can be a good choice when its supported operations match your use case, particularly for app-based automation. A REST-style request to enumerate a page’s web parts looks like:

GET https://graph.microsoft.com/v1.0/sites/{site-id}/pages/{page-id}/microsoft.graph.sitePage/webParts

Retrieve one web part with:

GET https://graph.microsoft.com/v1.0/sites/{site-id}/pages/{page-id}/microsoft.graph.sitePage/webParts/{webpart-id}

Update operations use a PATCH request and a JSON body that identifies a supported type, such as textWebPart or standardWebPart:

PATCH https://graph.microsoft.com/v1.0/sites/{site-id}/pages/{page-id}/microsoft.graph.sitePage/webParts/{webpart-id}
Content-Type: application/json

These are endpoint patterns, not ready-to-run PowerShell commands: first resolve the site, page, and web-part IDs, then send the correct payload using the Graph SDK or HTTP request method. Consult Microsoft’s documentation for the exact schema, API version, and permission requirements for each operation: web-part resource, get a web part, update a web part, and create a page web part.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Graph’s page API does not expose every editor capability or every SharePoint web part. Its documented supported set covers selected types—for example, Button, Call to Action, Divider, Image, People, Quick Links, Spacer, YouTube Embed, and Title Area in relevant operations. Unsupported components can cause a create or update request to fail. Check the current page creation documentation and supported web-part guidance rather than assuming that any part visible in SharePoint can be managed through Graph.

Verify, publish, and recover changes

  1. Re-read the page. Run Get-PnPPageComponent again and compare component count, type, and position with your recorded state.
  2. Check the library state. A changed page can still be a draft, checked out, or awaiting approval. Inspect the relevant Site Pages item, for example:
    Get-PnPListItem -List "Site Pages" -Id $pageItemId `
        -Fields "CheckoutUser", "_ModerationStatus", "_UIVersionString"
  3. Validate in the browser. Confirm the page renders correctly for the intended audience, not only for an editor or site owner.
  4. Publish through the site’s workflow. The exact publishing action depends on the library settings, permissions, and cmdlet version. Do not assume that modifying a page automatically publishes it.
  5. Recover deliberately. If the result is wrong, restore the prior version through the site’s version history or use your recorded component state and approved recovery procedure.

Before deleting or replacing components, test on a copy, preserve the page state, log the affected URL and component identifiers, and use -WhatIf only where the specific cmdlet supports it.

Production safeguards and troubleshooting

  • Large libraries: use paging, request only needed fields, and process incrementally by indexed ID or date where practical. Avoid repeatedly retrieving the whole library. Log progress and handle throttling with backoff rather than tight retry loops.
  • Idempotency: check whether a page part already exists before adding it, so reruns do not create duplicates.
  • Authentication: keep certificates and other credentials in an approved secret store; do not embed passwords in scripts. Test the unattended identity separately from your interactive account.
  • Version control: record module versions and validate cmdlet syntax and returned properties after upgrades. PnP cmdlet behavior can change.
  • Least privilege: grant only the necessary permissions and use a test site to validate consent and access.
Symptom Likely issue What to check
Access denied Missing site rights, API permission, or admin consent Confirm the connected tenant and identity, then check the operation’s permission requirements and sign-in/consent records.
Page or file not found Wrong site, identity, or URL form Check the connected site and whether the cmdlet expects a site-relative or server-relative path.
Command not recognized Module is missing or not loaded, or command differs by version Check that the correct module is installed and consult its current command help.
Graph rejects a web part Unsupported part type or invalid payload Compare the type and payload with the documented Graph page API; use PnP or the SharePoint editor if Graph does not support the scenario.
Change succeeded but readers see the old page Draft, checkout, approval, or version state Inspect the page item’s checkout and moderation state, then follow the site’s publishing workflow.
Repeated sign-in prompt or authentication failure Conditional access, app consent, tenant mismatch, or expired certificate Verify tenant and app configuration, try a manual interactive read, and inspect Entra sign-in logs.
Throttling or slow inventory Large unfiltered requests or too many rapid calls Reduce fields and query scope, page results, and add measured retry/backoff handling.

For SharePoint Server, use documentation for the exact server release and run server cmdlets in the appropriate SharePoint environment. Microsoft’s PowerShell resource index distinguishes Microsoft 365, SharePoint Server Subscription Edition, and older server references.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.