Microsoft OneDrive 환경 설정 삭제

모든 Microsoft OneDrive 환경 설정과 정보를 삭제하려면 보존된 파일을 다른 사용자에게 다시 할당한 후 사용자의 OneDrive 사이트를 제거하는 것이 좋습니다.

관리자는 PowerShell 스크립트SharePoint Client-Side CSOM(개체 모델) 명령을 사용하여 이러한 목록을 삭제할 수 있습니다. 필요한 모든 CSOM 어셈블리는 SharePointPnPPowerShellOnline Microsoft PowerShell 모듈에 포함되어 있습니다.

이 문서에 포함된 스크립트를 요구 사항에 맞게 조정할 수 있습니다. 예를 들어 다음과 같이 에 대한 정보를 추출할 user1@contoso.com 수 있습니다.

  1. 자기 자신에게 사용자의 OneDrive 계정 권한을 할당합니다. 이 작업은 여기에 설명된 대로 Microsoft 365 관리 센터에서 수행할 수 있습니다.

  2. 필요한 Microsoft PowerShell 모듈을 설치합니다.

    Install-Module SharePointPnPPowerShellOnline

    Install-Module CredentialManager

  3. 아래 DeleteODBLists PowerShell 스크립트(또는 해당 스크립트의 사용자 지정 버전)을 실행합니다. 예:

    $ODBSite = "https://contoso-my.sharepoint.com/personal/user1_contoso_com"

    DeleteODBLists -siteUrl $ODBSite

스크립트는 이러한 설정을 포함하는 숨겨진 목록을 영구적으로 삭제합니다.

중요

아직 조직에 있는 활성 사용자는 OneDrive 계정에서 이 스크립트를 실행하지 마세요.

DeleteODBLists 스크립트

아래 내용을 복사하여 텍스트 파일에 붙여넣습니다. 파일을 DeleteODBLists.ps1 저장합니다.

참고

로드되지 않는 어셈블리에 대한 오류가 표시되면 Add-Type 경로 매개 변수에 정의된 대로 최신 버전의 SharePointPnPPowerShellOnline PowerShell 모듈 경로를 다시 확인합니다. 컴퓨터에서 경로가 다를 수 있거나 다른 버전의 모듈을 사용하고 있을 수 있습니다(모듈 버전은 경로의 일부임).

#DeleteODBLists
#Deletes OneDrive experience settings, stored in several SharePoint Lists
param([string]$siteUrl, [bool]$useStoredCreds=$true)
Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SharePointPnPPowerShellOnline\2.26.1805.0\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SharePointPnPPowerShellOnline\2.26.1805.0\Microsoft.SharePoint.Client.Runtime.dll"

if (!$siteUrl)
{
    Write-Host "Please specify a OneDrive site using -siteUrl."
    return
}

if ($useStoredCreds)
{
    Write-Host "Retrieving stored Windows credentials for $siteUrl."
    $cred = Get-StoredCredential -Target $siteUrl
    if (!$cred)
    {
        Write-Host "Didn't find stored credential for $siteUrl. Please provide credentials to connect."
        $cred = Get-Credential
    }
}
else
{
   $cred = Get-Credential
}

$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($cred.UserName,$cred.Password)
$webURL = $siteUrl
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webURL)
$ctx.Credentials = $credentials

#Root folders of lists to export
$SWMRoot = "Reference " #starts with this string
$notificationsRoot = "notificationSubscriptionHiddenList6D1E55DA25644A22"
$activityFeedRoot = "userActivityFeedHiddenListF4387007BE61432F8BDB85E6"
$accessRequestsRoot = "Access Requests"
$microfeedRoot = "PublishedFeed"
$SPHomeCacheRoot = "SharePointHomeCacheList"
$sharingLinksRoot = "Sharing Links"
$socialRoot = "Social"


#Get all lists in the web
try{
    $lists = $ctx.web.Lists
    $ctx.load($lists)
    $ctx.executeQuery()
}
catch{
    write-host "$($_.Exception.Message)" -foregroundcolor red
}


#Process all lists and identify the settings lists to be deleted
$listsToDelete = @()
foreach($list in $lists)
{
    $ctx.load($list)
    $ctx.load($list.RootFolder)
    $ctx.executeQuery()
    $listTitle = [string]$list.Title
    $listRoot = $list.RootFolder.Name
    $listTemplateId = $list.TemplateFeatureId

    Write-host ("Processing List: " + $list.Title + " with " + $list.ItemCount + " items").ToUpper() -ForegroundColor Yellow
    Write-host (">> List Root Folder: " + $listRoot) -ForegroundColor Yellow

    if ($listRoot.StartsWith($SWMRoot,"CurrentCultureIgnoreCase") -and $list.ItemCount -ge 1)
    {
        Write-Host ">> Found: Shared With Me List" -ForegroundColor Green
        $listDetails = @{listType = "Shared With Me List"; listTitle = $listTitle; listRoot = $listRoot; listTemplateId = $listTemplateId}
        $listsToDelete += $listDetails
    }
    elseif ($listRoot -eq $notificationsRoot)
    {
        Write-Host ">> Found: Notifications List" -ForegroundColor Green
        $listDetails = @{listType = "Notifications List"; listTitle = $listTitle; listRoot = $listRoot; listTemplateId = $listTemplateId}
        $listsToDelete += $listDetails
    }
    elseif ($listRoot -eq $activityFeedRoot)
    {
        Write-Host ">> Found: User Activity Feed List" -ForegroundColor Green
        $listDetails = @{listType = "User Activity Feed List"; listTitle = $listTitle; listRoot = $listRoot; listTemplateId = $listTemplateId}
        $listsToDelete += $listDetails
    }
    elseif ($listRoot -eq $accessRequestsRoot)
    {
        Write-Host ">> Found: Access Requests List" -ForegroundColor Green
        $listDetails = @{listType = "Access Requests List"; listTitle = $listTitle; listRoot = $listRoot; listTemplateId = $listTemplateId}
        $listsToDelete += $listDetails
    }
    elseif ($listRoot -eq $microfeedRoot)
    {
        Write-Host ">> Found: MicroFeed List" -ForegroundColor Green
        $listDetails = @{listType = "Microfeed List"; listTitle = $listTitle; listRoot = $listRoot; listTemplateId = $listTemplateId}
        $listsToDelete += $listDetails
    }
    elseif ($listRoot -eq $SPHomeCacheRoot)
    {
        Write-Host ">> Found: SharePoint Home Cache List" -ForegroundColor Green
        $listDetails = @{listType = "SharePoint Home Cache List"; listTitle = $listTitle; listRoot = $listRoot; listTemplateId = $listTemplateId}
        $listsToDelete += $listDetails
    }
    elseif ($listRoot -eq $sharingLinksRoot)
    {
        Write-Host ">> Found: Sharing Links List" -ForegroundColor Green
        $listDetails = @{listType = "Sharing Links List"; listTitle = $listTitle; listRoot = $listRoot; listTemplateId = $listTemplateId}
        $listsToDelete += $listDetails
    }
    elseif ($listRoot -eq $socialRoot)
    {
        Write-Host ">> Found: Social List" -ForegroundColor Green
        $listDetails = @{listType = "Social List"; listTitle = $listTitle; listRoot = $listRoot; listTemplateId = $listTemplateId}
        $listsToDelete += $listDetails
    }
}

#Retrieve web features
$webFeatures = $ctx.Web.Features
$ctx.Load($webFeatures)
$ctx.ExecuteQuery()

#Export list function
function deleteList
{
    Param ([string] $listTitle, [string] $listTemplateId)

    Write-Host ("Deleting List: " + $listTitle).ToUpper() -ForegroundColor Red

    #Remove features the list may depend on
    $webfeatures.Remove($listTemplateId, $true)
    $ctx.executeQuery()

    #Set the list to allow deletion
    $list = $lists.GetByTitle($listTitle)
    $list.AllowDeletion = $true
    $list.Update()
    $ctx.executeQuery()

    #Delete the list
    $list.DeleteObject()
    $ctx.executeQuery()
}

#Delete all target lists
foreach ($list in $listsToDelete)
{
    deleteList -listTitle $list["listTitle"] -listTemplateId $list["listTemplateId"]
}