@@ -32,7 +32,7 @@ Organizations often lack visibility into the volume, ownership, and status of mo
3232
3333
3434
35- # [ PnP PowerShell] ( #tab/pnpps )
35+ # [ PnP PowerShell V2 ] ( #tab/pnpps2 )
3636``` powershell
3737
3838# ============================
@@ -143,6 +143,69 @@ catch {
143143
144144```
145145[ !INCLUDE [ More about PnP PowerShell] ( ../../docfx/includes/MORE-PNPPS.md )]
146+
147+ # [ PnP PowerShell] ( #tab/pnpps )
148+ ``` powershell
149+ $siteURL = "https://domain.sharepoint.com/"
150+ $username = "username@domain.onmicrosoft.com"
151+ $password = "********"
152+ $secureStringPwd = $password | ConvertTo-SecureString -AsPlainText -Force
153+ $creds = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $secureStringPwd
154+ $dateTime = "_{0:MM_dd_yy}_{0:HH_mm_ss}" -f (Get-Date)
155+ $basePath = "E:\Contribution\PnP-Scripts\Logs\"
156+ $csvPath = $basePath + "\SitePages" + $dateTime + ".csv"
157+ $global:sitePagesCollection = @()
158+
159+ Function Login() {
160+ [cmdletbinding()]
161+ param([parameter(Mandatory = $true, ValueFromPipeline = $true)] $creds)
162+ Write-Host "Connecting to Site '$($siteURL)'" -f Yellow
163+ Connect-PnPOnline -Url $siteURL -Credential $creds
164+ Write-Host "Connection Successful" -f Green
165+ }
166+
167+ Function GetSitePagesDetails {
168+ try {
169+ Write-Host "Getting site pages information..." -ForegroundColor Yellow
170+ $sitePages = Get-PnPListItem -List "Site Pages"
171+ ForEach ($Page in $sitePages) {
172+ $sitePagesInfo = New-Object PSObject -Property ([Ordered] @{
173+ 'ID' = $Page.ID
174+ 'Title' = $Page.FieldValues.Title
175+ 'Description' = $Page.FieldValues.Description
176+ 'Page Layout Type' = $Page.FieldValues.PageLayoutType
177+ 'FileRef' = $Page.FieldValues.FileRef
178+ 'FileLeafRef' = $Page.FieldValues.FileLeafRef
179+ 'Created' = Get-Date -Date $Page.FieldValues.Created_x0020_Date -Format "dddd MM/dd/yyyy HH:mm"
180+ 'Modified' = Get-Date -Date $Page.FieldValues.Last_x0020_Modified -Format "dddd MM/dd/yyyy HH:mm"
181+ 'Modified By' = $Page.FieldValues.Modified_x0020_By
182+ 'Created By' = $Page.FieldValues.Created_x0020_By
183+ 'Author' = $Page.FieldValues.Author.Email
184+ 'Editor' = $Page.FieldValues.Editor.Email
185+ 'BannerImage Url' = $Page.FieldValues.BannerImageUrl.Url
186+ 'File_x0020_Type' = $Page.FieldValues.File_x0020_Type
187+ })
188+ $global:sitePagesCollection += $sitePagesInfo
189+ }
190+ }
191+ catch {
192+ Write-Host "Error in getting site pages:" $_.Exception.Message -ForegroundColor Red
193+ }
194+ Write-Host "Exporting to CSV..." -ForegroundColor Yellow
195+ $global:SitePagesCollection | Export-Csv $csvPath -NoTypeInformation -Append
196+ Write-Host "Exported to CSV successfully!" -ForegroundColor Green
197+
198+ }
199+
200+ Function StartProcessing {
201+ Login($creds);
202+ GetSitePagesDetails
203+ }
204+
205+ StartProcessing
206+ ```
207+ [ !INCLUDE [ More about PnP PowerShell] ( ../../docfx/includes/MORE-PNPPS.md )]
208+
146209***
147210
148211## Output
0 commit comments