• 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)

    $ctx.Load($fieldChoice)
    Invoke-PnPQuery

    $choices = $fieldChoice.Choices
    $choices += "Bentley"

    $fieldChoice.Choices = $choices | Sort-Object

    $fieldChoice.UpdateAndPushChanges($true)
    Invoke-PnPQuery

  • 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"
    $schemaXml.Field.CHOICES.AppendChild($varNewChoice)

    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)
    {
    if($link.href.StartsWith("/"))
    {
    $newlink="https://MySiteSP"+$link.href;
    Write-Host($newlink);
    $statusCodeForSPURL = Invoke-WebRequest -Uri $newlink -UseDefaultCredentials  | select -ExcludeProperty StatusCode
    Write-Host($statusCodeForSPURL.StatusCode)
    Write-Host
    }
    elseif( $link.href.StartsWith("..") -Or $link.href.StartsWith("javascript") -Or $link.href.StartsWith("#"))
    {
    Write-Host("Invalid Url: "+$link.href)
    Write-Host
    
    }
    else
    {
    Write-Host($link.href)
    $statusCodeForNormalURL = Invoke-WebRequest -Uri $link.href  | select -ExcludeProperty StatusCode
    Write-Host($statusCodeForNormalURL.StatusCode)
    Write-Host
    }
    }
    
     
    
    ...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)
    {
    if($link.href.StartsWith("/"))
    {
    $newlink="https://MySPSite"+$link.href;
    $statusCodeForSPURL = Invoke-WebRequest -Uri $newlink -UseDefaultCredentials  | select StatusCode
    $newlink.innerText
    $newlink
    $statusCodeForSPURL
    Write-Host
    }
    else
    {
    $statusCodeForNormalURL = Invoke-WebRequest -Uri $link.href -UseDefaultCredentials  | select StatusCode
    $link.innerText
    $link.href
    $statusCodeForNormalURL
    Write-Host
    }
    
    }
  • Chip became a registered member 1 year, 5 months ago

    avataravatar
© 4sysops 2006 - 2021

CONTACT US

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

Sending

Log in with your credentials

or    

Forgot your details?

Create Account