【发布时间】:2017-06-22 08:06:31
【问题描述】:
如何通过powershell在线迁移sharepoint(Office 365)一个用户的驱动内容到另一个?
【问题讨论】:
标签: sharepoint-2010 office365 powershell-2.0
如何通过powershell在线迁移sharepoint(Office 365)一个用户的驱动内容到另一个?
【问题讨论】:
标签: sharepoint-2010 office365 powershell-2.0
在 TechNet 上查看此脚本。它列出了一些限制,但它应该给你一个很好的起点。
https://gallery.technet.microsoft.com/office/Copy-OneDrive-files-f1c751e7
以下是页面中的一些基本信息:
有几点需要牢记:
这可能需要一段时间。每个文件或文件夹至少需要一两秒的时间来处理。如果你的离开用户有数万 文件,时间不在你身边,你可能想使用另一个 方法。
它使用您的连接。它会先下载文件,然后再将它们上传到其他用户的 OneDrive。如果您的连接速度很慢,并且 您正在移动大文件,您可能希望将其保留在 云托管服务器。
它不能移动大于 250MB 的文件 这个 PowerShell 模块的一个限制是它不能将大于 250MB 的文件发送到 共享点。该脚本将记录这些文件并导出 如果您想移动它们,请将它们列表到 c:\temp\largefiles.txt 手动。
无双因素身份验证此脚本不适用于管理员帐户的多因素身份验证。你可能想要 为此目的创建一个没有 MFA 的临时管理员。
先决条件 要使此脚本正常工作,您需要安装 以下 PowerShell 模块:
SharePoint Online 命令行管理程序 SharePoint Online 管理 Shell 用于修改用户 OneDrive 站点的权限 收藏。
在此处下载并安装它: https://www.microsoft.com/en-au/download/details.aspx?id=35588
SharePoint PnP Powershell 模块 SharePoint PnP Powershell 模块 提供我们将用于传输文件和文件夹的 cmdlet OneDrive 帐户之间。
要安装它,请以管理员身份打开 PowerShell 窗口并运行 以下 cmdlet:
Install-Module SharePointPnPPowerShellOnline -ForceMSOnline V1 Powershell 模块您还需要 MSOnline V1 此脚本的 PowerShell 模块。
要安装它,请以管理员身份打开 PowerShell 窗口并运行 以下 cmdlet:
Install-Module MSOnline -Force
还有脚本本身:
$departinguser = Read-Host "Enter departing user's email"
$destinationuser = Read-Host "Enter destination user's email"
$globaladmin = Read-Host "Enter the username of your Global Admin account"
$credentials = Get-Credential -Credential $globaladmin
Connect-MsolService -Credential $credentials
$InitialDomain = Get-MsolDomain | Where-Object {$_.IsInitial -eq $true}
$SharePointAdminURL = "https://$($InitialDomain.Name.Split(".")[0])-admin.sharepoint.com"
$departingUserUnderscore = $departinguser -replace "[^a-zA-Z]", "_"
$destinationUserUnderscore = $destinationuser -replace "[^a-zA-Z]", "_"
$departingOneDriveSite = "https://$($InitialDomain.Name.Split(".")[0])-my.sharepoint.com/personal/$departingUserUnderscore"
$destinationOneDriveSite = "https://$($InitialDomain.Name.Split(".")[0])-my.sharepoint.com/personal/$destinationUserUnderscore"
Write-Host "`nConnecting to SharePoint Online" -ForegroundColor Blue
Connect-SPOService -Url $SharePointAdminURL -Credential $credentials
Write-Host "`nAdding $globaladmin as site collection admin on both OneDrive site collections" -ForegroundColor Blue
# Set current admin as a Site Collection Admin on both OneDrive Site Collections
Set-SPOUser -Site $departingOneDriveSite -LoginName $globaladmin -IsSiteCollectionAdmin $true
Set-SPOUser -Site $destinationOneDriveSite -LoginName $globaladmin -IsSiteCollectionAdmin $true
Write-Host "`nConnecting to $departinguser's OneDrive via SharePoint Online PNP module" -ForegroundColor Blue
Connect-PnPOnline -Url $departingOneDriveSite -Credentials $credentials
Write-Host "`nGetting display name of $departinguser" -ForegroundColor Blue
# Get name of departing user to create folder name.
$departingOwner = Get-PnPSiteCollectionAdmin | Where-Object {$_.loginname -match $departinguser}
# If there's an issue retrieving the departing user's display name, set this one.
if ($departingOwner -contains $null) {
$departingOwner = @{
Title = "Departing User"
}
}
# Define relative folder locations for OneDrive source and destination
$departingOneDrivePath = "/personal/$departingUserUnderscore/Documents"
$destinationOneDrivePath = "/personal/$destinationUserUnderscore/Documents/$($departingOwner.Title)'s Files"
$destinationOneDriveSiteRelativePath = "Documents/$($departingOwner.Title)'s Files"
Write-Host "`nGetting all items from $($departingOwner.Title)" -ForegroundColor Blue
# Get all items from source OneDrive
$items = Get-PnPListItem -List Documents -PageSize 1000
$largeItems = $items | Where-Object {[long]$_.fieldvalues.SMTotalFileStreamSize -ge 261095424 -and $_.FileSystemObjectType -contains "File"}
if ($largeItems) {
$largeexport = @()
foreach ($item in $largeitems) {
$largeexport += "$(Get-Date) - Size: $([math]::Round(($item.FieldValues.SMTotalFileStreamSize / 1MB),2)) MB Path: $($item.FieldValues.FileRef)"
Write-Host "File too large to copy: $($item.FieldValues.FileRef)" -ForegroundColor DarkYellow
}
$largeexport | Out-file C:\temp\largefiles.txt -Append
Write-Host "A list of files too large to be copied from $($departingOwner.Title) have been exported to C:\temp\LargeFiles.txt" -ForegroundColor Yellow
}
$rightSizeItems = $items | Where-Object {[long]$_.fieldvalues.SMTotalFileStreamSize -lt 261095424 -or $_.FileSystemObjectType -contains "Folder"}
Write-Host "`nConnecting to $destinationuser via SharePoint PNP PowerShell module" -ForegroundColor Blue
Connect-PnPOnline -Url $destinationOneDriveSite -Credentials $credentials
Write-Host "`nFilter by folders" -ForegroundColor Blue
# Filter by Folders to create directory structure
$folders = $rightSizeItems | Where-Object {$_.FileSystemObjectType -contains "Folder"}
Write-Host "`nCreating Directory Structure" -ForegroundColor Blue
foreach ($folder in $folders) {
$path = ('{0}{1}' -f $destinationOneDriveSiteRelativePath, $folder.fieldvalues.FileRef).Replace($departingOneDrivePath, '')
Write-Host "Creating folder in $path" -ForegroundColor Green
$newfolder = Ensure-PnPFolder -SiteRelativePath $path
}
Write-Host "`nCopying Files" -ForegroundColor Blue
$files = $rightSizeItems | Where-Object {$_.FileSystemObjectType -contains "File"}
$fileerrors = ""
foreach ($file in $files) {
$destpath = ("$destinationOneDrivePath$($file.fieldvalues.FileDirRef)").Replace($departingOneDrivePath, "")
Write-Host "Copying $($file.fieldvalues.FileLeafRef) to $destpath" -ForegroundColor Green
$newfile = Copy-PnPFile -SourceUrl $file.fieldvalues.FileRef -TargetUrl $destpath -OverwriteIfAlreadyExists -Force -ErrorVariable errors -ErrorAction SilentlyContinue
$fileerrors += $errors
}
$fileerrors | Out-File c:\temp\fileerrors.txt
# Remove Global Admin from Site Collection Admin role for both users
Write-Host "`nRemoving $globaladmin from OneDrive site collections" -ForegroundColor Blue
Set-SPOUser -Site $departingOneDriveSite -LoginName $globaladmin -IsSiteCollectionAdmin $false
Set-SPOUser -Site $destinationOneDriveSite -LoginName $globaladmin -IsSiteCollectionAdmin $false
Write-Host "`nComplete!" -ForegroundColor Green
【讨论】: