Share via

Sharepoint Powershell Login Credentials Issues - Script to automate stripping of file versions from Library

Anonymous
2022-07-05T06:28:01+00:00

Hi All,

Background:

We are a creative studio with very little IT resources.

Recently we encountered a storage limit issue all across our tenant due to versioning eating up way more storage space than normal. Since there was about ~25K file on the Tenant share, it would have been very difficult to manually fix this. We finally fixed this in the dumbest possible way via downloading and re-uploading all the files over 3 days. Microsoft Support Agent went beyond the normal support to find this script for us that would supposedly automate the removal of all file versions on every file in the Library. We ran into errors when we tried executing the script and it seems far as we can tell it's an authentication issue.

I figure I try to see if I can find an answer with the community first before attempting to start another ticket to see why we are getting errors with this script.

Sharepoint Powershell Management Shell is not really working with PS 7 but this can sort of be resolved by going to Windows Powershell or Import-Module microsoft.online.sharepoint.powershell -UseWindowsPowerShell in PS 7.

When executing the script under Windows Powershell, a login window would pop up and after entering credentials (password was cut and pasted to ensure no typo errors). I would get the following error


cmdlet Get-Credential at command pipeline position 1 Supply values for the following parameters: Credential New-Object : Cannot find type [Microsoft.SharePoint.Client.SharePointOnlineCredentials]: verify that the assembly containing this type is loaded. At C:\Users\XXXXXX\OneDrive\Documents\PowerShell\Automate Versioning Delete.ps1:8 char:9 + $Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCreden ... +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException     + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand Error Deleting version History! Cannot find type [Microsoft.SharePoint.Client.ClientContext]: verify that the assembly containing this type is loaded.


Here is the script on pastebin with identifiable stuff removed. https://pastebin.com/GYSfEYL6

Does anyone know what we did wrong?

Microsoft 365 and Office | SharePoint | For business | Other

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2022-07-05T10:16:29+00:00

    HI ShaguarWKL,

    This may be out of scope here. YOu can use below code or use pnp latest version to work.

    Also sharepointonlinecredentials are not more supporting I beleive you can use -interactive also instead of Credential .

    Please use your code as below.

    #Config Parameters

    $AdminSiteURL = "https://tenant-admin.sharepoint.com"

    $SiteURL = "https://tenant.sharepoint.com/sites/site"

    $LibraryName="Documents"

    $BatchSize = 500

    Connect-SPOService -Url $AdminSiteURL -Credential (Get-Credential) 

    $Site = Get-SPOSite -Identity $SiteURL

    try{

     #Setup the context

    }

    You can use pnp-powershell as well.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2022-07-05T09:33:24+00:00

    Dear ShaguarWKL,

    Good Day! Thanks for posting to Microsoft Community. We are happy to help you. From your description, it seems that you are using PowerShell script code to automate the removal of all file versions on every file in the Library, however, you encountered an error message which is related to authentication.

    Given this situation, we understand the inconvenience caused by it. However, since our category focuses on SharePoint general issues and built-in features, your question is related to Microsoft SharePoint PowerShell codes. To ensure you get professional help. We sincerely recommend submitting your question toQ&A Community which is a specific channel to handle such a situation, and the engineers in the related team will focus on your specific scenario and provide specific suggestions.

    At the same time, we noticed that you got the script code from the third-party community, you can also go to the third-party community to post your question, then check if the engineers in the third-party community may help you.

    If the scenario above is not consistent with yours, you can reply back and point it out. Thanks for your patience and understanding.Sincerely,Claire | Microsoft Community Moderator **Note: In the event that you're unable to reply to this thread, please ensure that your Email address is verified in the Community Website by clicking on Your Account Name > "My Profile" > "Edit Profile" > Add your Email Address > tick "Receive email notifications" checkbox > click on "Save".***

    Was this answer helpful?

    0 comments No comments