Goal: Starting from a fresh Windows PC, finish by running one PowerShell command that reads the title of a SharePoint site.
Who it's for: Anyone. You don't need PowerShell experience, just copy, paste and follow the screenshots.
At a glance
| Item | Details |
|---|---|
| ⏱️ Time needed | 15–20 minutes (first time) |
| 💻 Computer | Windows 10 / 11 |
| 👤 Account | A Microsoft 365 work account with access to the SharePoint site |
| 🔑 One-time admin help | Someone with Global Administrator (or an admin role that can grant consent) for Step 3 |
| 🎯 End result | (Get-PnPWeb).Title prints your site title |
The workflow

Workflow: install PowerShell 7, install PnP.PowerShell, register the Entra ID app, connect, read the site title
Key terms (30-second glossary)
| Term | What it means in plain English |
|---|---|
| PowerShell 7 | The modern command window from Microsoft. Not the same as the built-in "Windows PowerShell 5.1". |
| PnP.PowerShell | A free add-on (module) with 700+ SharePoint and Microsoft 365 commands. |
Connect-PnPOnline | The command that signs you in to a SharePoint site. Every other PnP command needs it first. |
| Entra ID app registration | An "ID card" for PnP PowerShell in your tenant. Since September 2024, every tenant needs its own. |
| Client ID | The ID number of that app registration. You pass it to Connect-PnPOnline. |
| Admin consent | A one-time approval by an admin that allows the app to access SharePoint. |
Step 1: Install PowerShell 7
Why not the built-in PowerShell?
| Windows PowerShell 5.1 | PowerShell 7 | |
|---|---|---|
| Comes with Windows | ✅ Yes | ❌ Install once |
| Runs PnP.PowerShell 3.x | ❌ No | ✅ Yes (needs 7.4.0 or later) |
| Window title | "Windows PowerShell" | "PowerShell" / "PowerShell 7" |
| Start command | powershell | pwsh |
If you run PnP commands in the old one, you get this error:
Install it
| # | Action |
|---|---|
| 1 | Open Start → type PowerShell → open Windows PowerShell (any window works for this step) |
| 2 | Check the latest version: winget search --id Microsoft.PowerShell --exact |
| 3 | Install: winget install --id Microsoft.PowerShell --source winget |
| 4 | Close the window. Open Start → type PowerShell 7 → open it |
| 5 | Confirm the version: $PSVersionTable.PSVersion → Major must be 7 |
winget search --id Microsoft.PowerShell --exact
winget install --id Microsoft.PowerShell --source winget
pwsh
$PSVersionTable.PSVersion
💡 Tip: Already inside Windows PowerShell? Just type
pwshand press Enter to switch to PowerShell 7 in the same window.
Step 2: Install the PnP.PowerShell module
Run this inside PowerShell 7:
Install-Module PnP.PowerShell -Scope CurrentUser -Force
Get-Module PnP.PowerShell -ListAvailable | Select-Object Name, Version
| Part | Meaning |
|---|---|
-Scope CurrentUser | Installs for you only, so no admin rights are needed |
-Force | Skips the "untrusted repository" prompt |
Get-Module ... -ListAvailable | Proves it installed and shows the version |
⚠️ Common mistake: Installing the module from Windows PowerShell 5.1 puts it in a different folder. PowerShell 7 then says
Connect-PnPOnline is not recognized. Always install from PowerShell 7.
Step 3: Create the Entra ID app registration (one time per tenant)
Pick one option.
| Option A: Azure portal | Option B: One command | |
|---|---|---|
| Best for | Visual learners, full control | Speed |
| Clicks | ~15 | 1 command + sign-in |
| Needs | Admin who can grant consent | Same |
Option A: Azure portal (click-by-click)
A1. Open App registrations
| # | Action |
|---|---|
| 1 | Go to https://portal.azure.com and sign in |
| 2 | In the top search bar type App registrations → open it |
| 3 | Click + New registration |
A2. Fill in the registration form
| Field | Value |
|---|---|
| Name | PnP.PowerShell (any name works) |
| Supported account types | Single tenant only (default) |
| Redirect URI → platform | Public client/native (mobile & desktop) |
| Redirect URI → value | http://localhost |
Click Register.
A3. Copy the Client ID
On the Overview page, copy Application (client) ID and save it in Notepad. You'll need it in Step 4. The Directory (tenant) ID is here too.
A4. Add the SharePoint permission
| # | Action |
|---|---|
| 1 | Left menu → API permissions → + Add a permission |
| 2 | Choose SharePoint |
| 3 | Choose Delegated permissions (you sign in as yourself) |
| 4 | Search AllSites → tick the permission you need (see table below) |
| 5 | Click Add permissions |
| Permission | What you can do | Admin consent? |
|---|---|---|
AllSites.Read | Read sites, lists, items (enough for this guide) | No |
AllSites.Write | Read + write list items | No |
AllSites.Manage | Read + write items and lists | No |
AllSites.FullControl | Everything, including site settings | Yes |
🔒 Least privilege: Start with
AllSites.Read. Add more only when you need it.
A5. Grant admin consent
Click ✓ Grant admin consent for <your org> → Yes. The Status column turns green: Granted for …
A6. Check the Authentication settings
| Where | What to check |
|---|---|
| Authentication → Redirect URI configuration | Mobile and desktop applications → http://localhost |
| Authentication → Settings | Allow public client flows = Enabled (needed for -DeviceLogin) |
Option B: One command (PnP does it for you)
Run in PowerShell 7 and sign in with an admin account when the browser opens:
Register-PnPEntraIDAppForInteractiveLogin -ApplicationName "PnP.PowerShell" -Tenant "contoso.onmicrosoft.com"
| What it does automatically | |
|---|---|
| Creates the app registration | ✅ |
| Adds redirect URI + default permissions | ✅ |
| Prompts you to grant consent | ✅ |
| Prints the Client ID at the end | ✅ Copy it |
💡 Add
-SharePointDelegatePermissions "AllSites.Read"to choose the exact permission.
Add-DeviceLoginif no browser pops up (sign in with a code instead).
Step 4: Connect to the SharePoint site
Replace the two values, then run:
Connect-PnPOnline -Url "https://contoso.sharepoint.com/sites/pub" -ClientId "<your-client-id>" -Interactive
| Parameter | Value to use |
|---|---|
-Url | Full site address from your browser, e.g. https://contoso.sharepoint.com/sites/pub |
-ClientId | The Application (client) ID from Step 3 |
-Interactive | Opens a Microsoft sign-in window → sign in with your work account |
No output = success. PowerShell just returns to the prompt.
No browser pop-up? Use a device code instead
Connect-PnPOnline -Url "https://contoso.sharepoint.com/sites/pub" -ClientId "<your-client-id>" -Tenant "contoso.onmicrosoft.com" -DeviceLogin
| # | Action |
|---|---|
| 1 | PowerShell shows a code, e.g. ABCD1234 |
| 2 | Open https://microsoft.com/devicelogin in any browser |
| 3 | Enter the code → sign in → return to PowerShell |
Step 5: Read the site title 🎯
(Get-PnPWeb).Title
✅ You did it. You're connected, and PowerShell printed the site title.
Bonus: a few more read-only commands to try
| Command | Shows |
|---|---|
Get-PnPWeb -Includes Created | Select Title, Url, Created | Title, address, creation date |
Get-PnPList | Select Title, ItemCount | All lists and libraries with item counts |
Get-PnPSiteCollectionAdmin | Site collection admins |
Disconnect-PnPOnline | Signs out of the session |
Save it as a reusable script
Save as Get-SiteTitle.ps1, then run .\Get-SiteTitle.ps1 from PowerShell 7:
param(
[string]$SiteUrl = "https://contoso.sharepoint.com/sites/pub",
[string]$ClientId = "<your-client-id>",
[string]$Tenant = "contoso.onmicrosoft.com",
[switch]$DeviceLogin
)
if (-not (Get-Module -ListAvailable PnP.PowerShell)) {
Install-Module PnP.PowerShell -Scope CurrentUser -Force
}
Import-Module PnP.PowerShell
if ($DeviceLogin) {
Connect-PnPOnline -Url $SiteUrl -ClientId $ClientId -Tenant $Tenant -DeviceLogin
} else {
Connect-PnPOnline -Url $SiteUrl -ClientId $ClientId -Interactive
}
$web = Get-PnPWeb -Includes Title, Url, Created
Write-Host "Title : $($web.Title)"
Write-Host "Url : $($web.Url)"
Write-Host "Created : $($web.Created)"
Disconnect-PnPOnline
💡 Skip typing
-ClientIdevery time. Save it once as an environment variable, then open a new PowerShell 7 window:
[Environment]::SetEnvironmentVariable("ENTRAID_APP_ID", "<your-client-id>", "User")
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
Connect-PnPOnline is not recognized | You're in Windows PowerShell 5.1, or the module was installed there | Type pwsh, then re-run Install-Module PnP.PowerShell -Scope CurrentUser -Force |
pwsh is not recognized right after install | PATH not refreshed | Close and reopen the window, or open PowerShell 7 from Start |
AADSTS700016: Application ... not found | Wrong Client ID or wrong tenant | Copy the Client ID again from Overview |
AADSTS65001: ... has not consented | Admin consent missing | API permissions → Grant admin consent |
AADSTS7000218: ... client_assertion or client_secret | Public client flows disabled (device login) | Authentication → Settings → Allow public client flows = Enabled |
403 Forbidden / Access denied | Your account has no access to that site | Ask the site owner to add you as a member/visitor |
running scripts is disabled on this system | Execution policy | Set-ExecutionPolicy -Scope CurrentUser RemoteSigned |
| Sign-in window never appears | Pop-up blocked / remote session | Use -DeviceLogin |
Cheat sheet
| Task | Command |
|---|---|
| Install PowerShell 7 | winget install --id Microsoft.PowerShell --source winget |
| Switch to PowerShell 7 | pwsh |
| Check version | $PSVersionTable.PSVersion |
| Install PnP | Install-Module PnP.PowerShell -Scope CurrentUser -Force |
| Update PnP | Update-Module PnP.PowerShell |
| Create the app (one command) | Register-PnPEntraIDAppForInteractiveLogin -ApplicationName "PnP.PowerShell" -Tenant "contoso.onmicrosoft.com" |
| Connect (browser) | Connect-PnPOnline -Url "<site-url>" -ClientId "<client-id>" -Interactive |
| Connect (device code) | Connect-PnPOnline -Url "<site-url>" -ClientId "<client-id>" -Tenant "<tenant>.onmicrosoft.com" -DeviceLogin |
| Site title | (Get-PnPWeb).Title |
| Sign out | Disconnect-PnPOnline |
References
| Source | Link |
|---|---|
| Install PowerShell 7 on Windows (Microsoft Learn) | https://learn.microsoft.com/powershell/scripting/install/install-powershell-on-windows |
| PnP PowerShell: Installation | https://pnp.github.io/powershell/articles/installation.html |
| PnP PowerShell: Register an Entra ID application | https://pnp.github.io/powershell/articles/registerapplication.html |
Connect-PnPOnline reference | https://pnp.github.io/powershell/cmdlets/Connect-PnPOnline.html |
| Grant tenant-wide admin consent (Microsoft Learn) | https://learn.microsoft.com/entra/identity/enterprise-apps/grant-admin-consent |
Tags: #SharePointOnline #PnPPowerShell #PowerShell7 #EntraID #Microsoft365 #M365Admin












No comments:
Post a Comment