• What about a simple copy library from one site collection to another…that’ll work for the moment?

    I’ve been searching for scripts, and nothing working so far.

    PnP seems like would be super concise option for this.

  • We are dealing with SharePoint OnPrem / 2016 in this scenario.

    I have a library template located in Site Collection 1, and need to create a library in site collection 2 using this centrally located .pst file in Site Collection 1.

    Every example I’ve seen so far has the .pst in the same site collection, but our scenario the .pst will stay in site collection 1 so there’s one source of truth.

    Is this an option? Does the .pst have to be in the same site collection where the new library is created if using PnP?

    Please advise of any example where I could accomplish this.

    Connect-PnPOnline -Url https://OurSiteORIG -CurrentCredentials
    Get-PnPFile -Url /_catalogs/lt/TempLibrary_100Rows.stp -Path c:temp -FileName TempLibrary_100Rows.stp -AsFile -Force

    #Now the .stp file is downloaded, upload it to destination and create library
    Connect-PnPOnline -Url https://OurSiteDest -CurrentCredentials
    Add-PnPFile -Path c:tempTempLibrary_100Rows.stp -Folder “_catalogs/lt”
    New-PnPList -Title “MyNewLibrary” -Template TempLibrary_100Rows -OnQuickLaunch


    Please advise of any example where I could accomplish this, as I’m getting the following error:

    New-PnPList : Cannot bind parameter ‘Template’. Cannot convert value “TempLibrary_100Rows” to type “Microsoft.SharePoint.Client.ListTemplateType”. Error: “Unable to
    match the identifier name TempLibrary_100Rows to a valid enumerator name. Specify one of the following enumerator names and try again:

  • *** Update >> Was able to get this code to both add value and sort:

    Connect-PnPOnline -Url “https://ourtenant.sharepoint.com/sites/Sandbox” -UseWebLogin
    $field = Get-PnPField -List “Space Request Form” -Identity “Schedule”
    $ctx = Get-PnPContext

    $fieldChoice = [Microsoft.SharePoint.Client.ClientContext].GetMethod(“CastTo”).MakeGenericMethod([Microsoft.SharePoint.Client.FieldChoice]).Invoke($ctx, $field)


    $choices = $fieldChoice.Choices
    $choices += “Bentley”

    $fieldChoice.Choices = $choices | Sort-Object


  • We are using this below script to add new values to our choice column, but need the option to sort the SharePoint list column choice values ascending. There are over 150 values, and just putting new values on the end/bottom of the dropdown isn’t user friendly.


    Connect-PnPOnline -Url “https://MySite/sites/Sandbox” -UseWebLogin
    $field = Get-PnPField -List aaa-f31e-4cc0-b193-bbb -Identity Schedule
    [xml]$schemaXml = $field.SchemaXml

    $varNewChoice = $schemaXml.CreateElement(“CHOICE”)
    $varNewChoice.InnerText = “Thursday”

    Set-PnPField -List aaa-f31e-4cc0-b193-bbb -Identity Schedule -Values @{SchemaXml=$schemaXml.OuterXml}


  • Hi Leos,

    Looks like problem with SharePoint links is anything internal will go to a ‘PageNotFound.aspx’ page, which will show 200

  • Hi Leos,

    Thanks for the help on this.

    I’m trying to following:

    $downloadURL     = 'https://MySiteSP/Pages/Documents%20and%20Forms.aspx'
    $downloadRequest = Invoke-WebRequest -Uri $downloadURL -UseDefaultCredentials
    #$allLinks = $downloadRequest.Links | Select innerText, href  | Format-table -AutoSize
    $allLinks = $downloadRequest.Links | ? { $_.href -like '/*' -or  $_.href -like 'http*' } | Select href | Format-table -AutoSize
    foreach ($link in $allLinks)
    $statusCodeForSPURL = Invoke-WebRequest -Uri $newlink -UseDefaultCredentials  | select -ExcludeProperty StatusCode
    elseif( $link.href.StartsWith("..") -Or $link.href.StartsWith("javascript") -Or $link.href.StartsWith("#"))
    Write-Host("Invalid Url: "+$link.href)
    $statusCodeForNormalURL = Invoke-WebRequest -Uri $link.href  | select -ExcludeProperty StatusCode
    ...but get error message:
    You cannot call a method on a null-valued expression.
    At C:ScriptsFind404s.ps1:7 char:15
    +            if($link.href.StartsWith("/"))
    +               ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
  • We have to check all the links on a SharePoint safety page in our SharePoint site before an audit to make sure they’re functioning. We are looking for some type of automated scrubbing as right now we manually click each link, but there are almost 100 links.

    My ‘where’ clause isn’t filtering out the URLs starting with “javascript()” or “…/”

    Also, every status code is 200, and I even changed the URL to be incorrect…still pulled back 200…was expecting 404

    $downloadURL     = 'https://MySPSite/Pages/Documents%20and%20Forms.aspx'
    $downloadRequest = Invoke-WebRequest -Uri $downloadURL -UseDefaultCredentials
    $allLinks = $downloadRequest.Links | ? { $_.href -like "/*" -or  $_.href -like "http*" } | Select href
    foreach ($link in $downloadRequest.Links)
    $statusCodeForSPURL = Invoke-WebRequest -Uri $newlink -UseDefaultCredentials  | select StatusCode
    $statusCodeForNormalURL = Invoke-WebRequest -Uri $link.href -UseDefaultCredentials  | select StatusCode
  • Chip became a registered member 2 years, 2 months ago

© 4sysops 2006 - 2022


Please ask IT administration questions in the forums. Any other messages are welcome.


Log in with your credentials


Forgot your details?

Create Account