0

I am currently working on a script that should remove an anonymous link from SharePoint using Powershell. I don't know where to start and i would like to know if somebody has an idea on how to do it.

The goal of the script is that we should remove entirely a link, i know microsoft can remvove the access after a few day but the link still exists it is just expired. I would like to destroy this link in order to be able to create another one

thanks in advance :)

0

Sample PowerShell script to remove anonymous link for specific file.

Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

    $username = "admin@xxx.onmicrosoft.com" 
    $password = "Password" 
    $url = "https://xxx.sharepoint.com/sites/lee"

    $securePassword = ConvertTo-SecureString $Password -AsPlainText -Force 

    $clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url) 
    $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword) 
    $clientContext.Credentials = $credentials 

    [Microsoft.SharePoint.Client.Web]::DeleteAllAnonymousLinksForObject($clientContext, "https://xxx.sharepoint.com/sites/lee/MyDoc2/testdata.xlsx")
    $clientContext.ExecuteQuery()
    Write-Host "-----"
1
  • Hey thanks for your answer, i am trying what you gave and i have the following error : Exception calling "ExecuteQuery" with "0" argument(s): "The remote server returned an error: (400) Bad Request." At C:\Users\XXXXXXXXXXXX\Desktop\Link.ps1:15 char:5 + $clientContext.ExecuteQuery() + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WebException I don't understand why i have this can you explain it to me pliz Thanks in advance – Just a Random Guy May 22 '20 at 9:13
0

Hey thanks for your answer, i am trying what you gave and i have the following error :

Exception calling "ExecuteQuery" with "0" argument(s): "The remote server returned an error: (400) Bad Request." At C:\Users\XXXXXXXXXXXX\Desktop\Link.ps1:15 char:5 + $clientContext.ExecuteQuery() + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WebException

I don't understand why i have this can you explain it to me pliz

Thanks in advance

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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