I've written some code using PnP PowerShell for SharePoint Online, but I now need to port it to SharePoint 2013. While I had full control on SharePoint Online, I have no Admin rights to SharePoint 2013.

The following code simply iterates through a Site collection and sub-webs and finds lists that support a particular content type. It then outputs the contents of each list into a Report.

I'm confused about connecting to SharePoint on-prem. Online I'm using:

 Connect-PnPOnline -Url $sourceUrl -CurrentCredentials

Assuming SharePoint 2013 is running Powershell 5.1, Other than the connection there really isn't much to change? Is there?

 Get-SPOnlineFileDetails -sourceUrl "http://intranet.xxxx.gov/km/" -Recurse $true -IncludeFileSize $true | Export-Csv -NoTypeInformation -Path "C:\Users\wxmuldom\Documents\Data\SPOnlineDetails.csv"

    function Get-SPOnlineFileDetails()
            [Parameter(Mandatory=$true,ValueFromPipeline, HelpMessage="SharePoint Online source site URL")]
             Write-Host "###################### Pull Details From SharePoint Online ######################" -ForegroundColor Green
             Write-Host "Provided Source URL :"$sourceUrl -ForegroundColor Green

                     Connect-PnPOnline -Url $sourceUrl -CurrentCredentials
                     $web = Get-PnPWeb

                     PopulateData -web $web -incldeFileSize $IncludeFileSize

                     if($Recurse -eq $false){
                         Get-PnPSubWebs | %{
                          PopulateData -web $_ -incldeFileSize $IncludeFileSize                   
                         Get-PnPSubWebs -Recurse | %{
                          PopulateData -web $_ -incldeFileSize $IncludeFileSize                   
                Write-Host $_.Exception.Message -ForegroundColor Red


    function PopulateData($web, $incldeFileSize){
            Write-Host "Current Site " $web.url -ForegroundColor Cyan 
                      $libs = Get-PnPList -Web $web | Where{($_.BaseType -eq “DocumentLibrary”) }

                      foreach($lib in $libs){
                         $libitems = (Get-PnPListItem -Web $web -List $lib -Fields "FileLeafRef","Name","Title","Author","Modified","Created","KBAbstract","KBContentAuthor","KBCategory","Publish","KBPublishDate").FieldValues

                           foreach($libitem in $libitems)
                                 if($libitem.FSObjType -eq "0"){
                                  $data = @{
                                              "Web Name" = $web.Title

                                              "Library Name" = $lib.Title
                                              "File Name" = $libitem.FileLeafRef
                                              "Abstract" = $libitem.KBAbstractMicrosoft.SharePoint.Client.FieldUserValue
                                                $value = $libitem["KBContentAuthor"]
                                                $user = Get-PnPUser -Identity $value.LookupId
                                               "Content Author" = $user.Title
                                               $MMSFieldValueColl = $libitem["KBCategory"] 
                                                #Concatenate each term in the value collection
                                                $MMSFieldTerms = ""
                                                Foreach ($MMSFieldValue in $MMSFieldValueColl) {

                                                    if($MMSFieldValue.label -ne $null)
                                                        $MMSFieldTerms+=$MMSFieldValue.label+"; "
                                                Write-Host $MMSFieldTerms

                                             # "Knowledge Area" = $libitem.KBCategory
                                              "Publish" = $libitem.Publish
                                              "Published Date" = $libitem.KBPublishedDate.LookupValue
                                              "File URL" = $libitem.FileRef
                                              "Modified Date" = $libitem.Modified
                                              "Created By" = $libitem.Author.LookupValue
                                              "Created Date" = $libitem.Created
                                              "Modified By" = $libitem.Editor.LookupValue
                                              "File Size (KB)" = $null
                                 if($incldeFileSize -eq $true){
                                        $file = Get-PnPFile -Url $libitem.FileRef
                                        $data["File Size (KB)"] = $file.Length / 1KB
                                  New-Object PSObject -Property $data

2 Answers 2


Just install the right module. See the installation instructions here, and note that there's a different installation on the PNP modules for each version of SP, including 2013. Note, if you need multiple installations on the same machine, that can get a bit tricky, so see the answers here if you need that option.


If anyone is looking to connect to the on-Prem 2013 instance using PnP.PowerShell, use the -TransformationOnPrem -CurrentCredential switches as shown in the Pnp.PowerShell docs

Connect-PnPOnline -Url "https://portal.contoso.com" -TransformationOnPrem -CurrentCredential

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.