OneDrive version 삭제

꽁자 5TB OenDrive 파일 버전 관리로 인해 용량이 줄어들때 일일히 버전 파일을 삭제 하기란 매우 힘든일이다.

PowerShell  에서 아래와 같이 한다.

SharePoint Online Client Components SDK 를 먼저 설치한다.

https://www.microsoft.com/en-us/download/details.aspx?id=42038


아래와 같이 PowerShell 스크립트를 실행하면 모든 버전 파일이 for loop 을 돌면서 삭제된다.

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"

   

#Config Parameters

$SiteURL= "https://yoursharepont-my.sharepoint.com/personal/yourid_domain_com/"

$LibraryName="Documents"


#Setup Credentials to connect

$Cred = Get-Credential

$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

  

    #Setup the context

    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)

    $Ctx.Credentials = $Cred

  

    #Get the web and Library

    $Web=$Ctx.Web

    $List=$web.Lists.GetByTitle($LibraryName)

   

    $Query = New-Object Microsoft.SharePoint.Client.CamlQuery

    $Query.ViewXml="<View Scope='RecursiveAll'><Query><Where><Eq><FieldRef Name='FSObjType'/><Value Type='Integer'>0</Value></Eq></Where></Query></View>"

    $ListItems = $List.GetItems($Query)

    $Ctx.Load($ListItems)

    $Ctx.ExecuteQuery() 

    

    #Loop through each file in the library

    Foreach($Item in $ListItems)

    {      

    Start-Sleep -s 1

        #Get all versions of the file

        $Ctx.Load($Item.File)       

        $Ctx.Load($Item.File.Versions)

        $Ctx.ExecuteQuery()

        Write-host "Processing Item:" $Item.file.Name

  

        #Delete all versions of the file

#        If($Item.File.Versions.count -gt 0)

#        {

            $Item.File.Versions.DeleteAll()

            $Ctx.ExecuteQuery()

            Write-host -f Green "All Versions deleted on "$Item.file.Name

Start-Sleep -s 3

#        }

    }   


댓글

이 블로그의 인기 게시물

스노우쿨링 장소로 유명한 마우이 카팔루아 비치 (Kapalua Beach)

샌프란시스코 길로이 아울렛 Gilroy Outlet

하와이 로컬 슈퍼마켓 푸드랜드 팜스 (Foodland Farms) 연구