sharepoint online – Move entire Library contents with PnP PowerShell

Our company is doing a migration from SharePoint sub-sites to new sites.

The only things being moved are document libraries, since we’ll be moving a lot of libraries I have looked into doing this with PowerShell.

I have been using PnP PowerShell with Move-PnPFile. But I’m struggling to move an entire library worth of content. I can only get PowerShell to work for individual folders/files within the library.

I have tried to list items and loop through them to move, but I cannot seem to get this working either.

I’d like to move the library from https://companyname.sharepoint.com/IT/Test to https://companyname.sharepoint.com/sites/IT/Test

Connect-PnPOnline -Url 'https://companyname.sharepoint.com/IT' -UseWebLogin

$sourceUrl = 'https://companyname.sharepoint.com/IT/Test/'
$targetUrl = 'https://companyname.sharepoint.com/sites/IT/Test/'

$allDocs = (Get-PnPListItem -List 'Test').FieldValues

foreach ($item in $allDocs)
{
    Move-PnPFile -SourceUrl ($sourceUrl + $item.FileLeafRef) -TargetUrl ($targetUrl + $item.FileLeafRef) -Force
}

Basically this is what I am trying to achieve. I have tried all sorts of different variations of ways to get items name/path, used relative URLs, different URLs, none has worked for me. (Get-PnPListItem also lists all items, I only need top level files/folders as all sub-files will move with the folder)

I have full admin access permission to both sites, and I am a global administrator.

How to upload a static HTML site using only PnP Powershell access?

As per the link you cited, there are only a few places you can upload an .aspx file where it will execute and display the file as a page.

Of the locations enumerated in your cited link, I would suggest the Style Library.

Add-PnpFile -Path “C:<Local Path to file>test.aspx” -Folder “/sites/MySite/Style Library/“ -Connection $MyConnection

This will upload the file to the Style Library in that site. If the file already exists, it will be overwritten.

Please mark as Answer if this solved your problem.

Chrome Extension and PnP JS

I am building a chrome extension for SPO. It has multiple html pages and I need to make PnP JS(SP Rest API) calls. I am using react app.
I was able to read the cookies FedAuth and rtFa from content script (content.js). Now how do I pass these cookies to every PnP JS call I make from html pages?

pnp powershell – Set SP online site collection as read only with only SCA rights

We have a requirement to set SP online sites to read-only post migration to another tenant. We have Site collection admin rights and we need to do this for 100 sites a week. We need to avoid the manual effort of creating site policies. So far the 2 automated options for us are –

  1. Connect-SPOService “https://$tenant-admin.sharepoint.com”

    Set-SPOSite $siteUrl -LockState “ReadOnly”

However, we wont be provided the tenant admin rights so cant use the connect-sposervice command.

  1. Activate the site policy feature at the site collection level, create a site policy manually in each site collection and then activate the policy using the script below.

$SitePolicyToActivate = Get-PnPSitePolicy -Name $PolicyName | Select-Object -Property Name

However, we would need to avoid the manual effort of creating the site policy. We checked that the content type hub is not enabled for the tenant and we cant publish the policy across any site collections.

Is there a feasible automated way to achieve activating the site policy using script with only Site collection admin rights? Any help in this regard is appreciated.

Setting up taxonomy field with Pnp PowerShell in SharePoint Online and Teams

I am using PnP to set up a number of site collections with the same set of site columns and content types. Initially I created an XML provisioning file from a site I set up, but when I applied it to another site there were issues adding the content types and creating some site columns that were using the term store to lookup values.
So now I am trying to set up the site columns and content types using Pnp PowerShell instead.

I could use some help translating some of the fields in the provisioning xml file to a PnP PowerShell command.

I wonder how to specify the -ID, should I use curly brackets or not? And how should I specify the -TermSetPath?
In the term store, I have a node XXX, where I have the term set Classification accessible for all sites in my hub. But since this is not open for everyone to add terms, I am planning on finding some PnP command to move those locally for each site.
So I will store “Classification” under the “Site Collection – xx.xxx.com-sites-thisSite” node. In the provisioning xml this is specified as {termsetid:{sitecollectiontermgroupname}:Classification}. How do I specify that to the Pnp command?

This is what I got:

The PnP PowerShell command:
Add-PnPTaxonomyField -DisplayName "Classification" -InternalName "Classification" -Group "XXX" -ID "cd165a06-9295-438b-90ef-20786be3a1fc" -TermSetPath "TestTermGroup|TestTermSet"

From the provisioning XML file:

<Field Type="TaxonomyFieldType" DisplayName="Classification" List="{{listid:TaxonomyHiddenList}}" WebId="{siteid}" ShowField="Term1033" Required="FALSE" EnforceUniqueValues="FALSE" Group="XXX" ID="{cd165a06-9295-438b-90ef-20786be3a1fc}" SourceID="{{siteid}}" StaticName="Classification" Name="Classification" Description="'Classification' is used to specify ...">
          <Default>
          </Default>
          <Customization>
            <ArrayOfProperty>
              <Property>
                <Name>SspId</Name>
                <Value xmlns:q1="http://www.w3.org/2001/XMLSchema" p4:type="q1:string" xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">{sitecollectiontermstoreid}</Value>
              </Property>
              <Property>
                <Name>TermSetId</Name>
                <Value xmlns:q2="http://www.w3.org/2001/XMLSchema" p4:type="q2:string" xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">{termsetid:{sitecollectiontermgroupname}:Classification}</Value>
              </Property>
          </Customization>
        </Field> 

And there is also another field generated in the provisioning xml, that seems coupled with the field I am trying to add. Do I need to add this field as well?
<Field Type="Note" DisplayName="Classification_0" StaticName="cd165a069295438b90ef20786be3a1fc" Name="cd165a069295438b90ef20786be3a1fc" ID="{72bd59fd-153c-4ab6-b49b-c40cd77853c8}" ShowInViewForms="FALSE" Required="FALSE" Hidden="TRUE" CanToggleHidden="TRUE" SourceID="{{siteid}}" />

And (a bonus question) the List="{{listid:TaxonomyHiddenList}}" from the provisioning xml file, how is that translated to the PnP command? Do I need to resolve listid to something?

sharepoint online – PnP PowerShell commands for set theme, remove sections of page and uninstall app not working

In the newest version of pnp powershell (1.7.0), I am trying these commands

Changing theme to one of the out of the box ones

Set-PnPWebTheme -Theme "Teal"

But if I use a name of a custom theme I’ve deployed, it works

Remove sections of the page

$pg = Get-PnPPage -Identity "Home"
$sectionsCount = $pg.Sections.Count
for($i=$sectionsCount-1; $i -ge 0; $i--) {
    write-host $i
    $pg.Sections.RemoveAt($i)
}
$page = Set-PnPPage -Identity $pg -Publish

Remove an add-in (spfx extension) from a site (not app catalogue)

Uninstall-PnPApp -Identity 150520F1-9488-423C-8006-AC541078B029

But they all do not work. The first one gives a unknown error. The other two does nothing. Does anyone know what’s wrong?

PNP React Web Parts in SharePoint Online suddenly stop working

I compiled a PNP sample for SharePoint on GitHub and published it in SharePoint as an app. I was able to insert it and it ran. After about half a year, the Web Part is no longer running. It shows an empty area. In edit mode of the page I only get the error message that something is no longer working.
I have already recompiled and renewed it. But without success.

Does anyone have any idea what that could be?

complexity theory – Is $P=NP$ even if we need infinitely many algorithms?

I’ll start with your first question:

If $P=NP$ was proven with an algorithm, would that have to mean that there is one algorithm that has to work for all inputs of length $n$?

Yes, in order for $P$ to equal $NP$, there has to be one algorithm for all inputs. It can’t be infinitely many algorithms that each solve some subset of the problem.

For your more specific question, though, you may be surprised: we already do have an algorithm that solves SAT for each specific value of $n$ and runs in polynomial time! In fact, we have an algorithm for each specific $n$ that works in constant time. Take $n = 3$, for example. Then just write out all the possible inputs of length $3$, and make a table of all the answers for each input. The algorithm just looks at the input, queries the table, and returns the result:

$$
begin{array}{cc}
text{input} & text{answer} \
000 & 0 \
001 & 1 \
010 & 1 \
011 & 0 \
cdots
end{array}
\
text{Algorithm: on input $x$ of length 3, return the answer given in the above table.}
$$

What went wrong here? The problem lies in what we mean by polynomial time. Hidden in the word “polynomial” is that we usually mean polynomial in $n$, i.e. it has to run in time that is a polynomial function of the input length. If the input length is a fixed constant, then it no longer makes sense to ask for a polynomial time algorithm: all algorithms (no matter how fast or slow) will be polynomial time since there are only finitely many possible inputs we care about, so the running time is always bounded by a constant.

pnp powershell – PnP Cmdlets / Provisioning: What are the minimal required permissions for basic SharePoint operations?

So far I mostly used PnP provisioning with interactive login (=a user logs in) which worked fine.

I now want to PnP-provision some folders and content types using application permissions with the least permissions possible. Also, MS Graph should be used.

To connect I use a certificate and clientId of my app:

Connect-PnPOnline -Url "https://tenant.sharepoint.com/sites/thesite" -Tenant "tenant.onmicrosoft.com" -ClientId <id of AAD registered app> -Thumbprint <cert thumbprint>

It connects fine.

But I am not able to do much using PnP cmdlets. So far I tried using Sites.ReadWrite.All and Sites.Manage.All as app permission but was not able to create event a single list item using New-PnPListItem. Far away from Invoke-PnPSiteTemplate. I always get 401 errors:

Add-PnPListItem: The remote server returned an error: (401)
Unauthorized.

Is there a certain minimal Graph permission level that needs to be present for PnP to work at all? Is a minimal permission approach feasable when working with PnP?

I’m aware that more permissions are needed the more I want to do in SharePoint. But for SharePoint there are not so many available:
enter image description here

For basic stuff I’d expect Sites.ReadWrite.All or Sites.Manage.All to succeed. Or not?