[玩转系统] 如何通过 PowerShell 将 OneDrive 文件传输给其他用户
作者:精品下载站 日期:2024-12-14 22:46:22 浏览:14 分类:玩电脑
如何通过 PowerShell 将 OneDrive 文件传输给其他用户
将文件从 Microsoft OneDrive 帐户传输到其他用户很容易,因为您可以从 OneDrive 下载内容,然后手动将其上传到其他帐户。在这篇文章中,我们将向您展示如何通过 PowerShell 将 OneDrive 文件传输给其他用户。
需要考虑的事项
当将文件从 OneDrive 上传到另一个帐户时,这是一项需要一些时间的任务,因为目前无法上传大于 250MB 的文件。好消息是 PowerShell 会记录所有无法上传的文件,因此您可以找到它们并通过常规方法共享它们。
在将文件上传到其他 OneDrive 帐户之前,文件将首先下载到您的计算机,因此请确保您的硬盘或 SSD 上有足够的空间,然后再继续。由于需要互联网连接,因此整体传输速度将取决于网络质量。
现在,我们必须注意,管理员帐户上不存在双因素身份验证,因此仅出于此目的创建一个没有 2FA 的临时管理员帐户。
你需要的东西
我们将使用特殊脚本将文件从一个 OneDrive 帐户移动到另一个帐户。因此,为了使脚本能够解决问题,请立即安装以下 PowerShell 模块:
SharePoint PnP PowerShell 模块
以管理员身份打开 PowerShell 工具,然后运行以下命令:
Install-Module SharePointPnPPowerShellOnline -Force
SharePoint Online Management Shell
该工具的目的是修改用户 OneDrive 帐户的权限。
从 microsoft.com 免费下载并安装它。
MSOnline V1 Powershell模块
为了安装这个最终模块,请以管理员身份在 PowerShell 中运行以下命令:
Install-Module MSOnline -Force
如何将 OneDrive 文件转移到另一个帐户
要将文件从您的 OneDrive 帐户传输到另一个帐户,您必须打开 PowerShell,然后运行提供的脚本。
打开 PowerShell
打开 Visual Studio Code 或 PowerShell。
您可以通过单击“搜索”按钮,然后搜索 PowerShell 来执行此操作。
从那里,右键单击该应用程序,然后选择旨在以管理模式打开该工具的选项。
运行脚本
接下来,您必须运行相关脚本。您可以在文章底部找到它。
我们选择这样做是因为脚本相当长。
添加脚本后,按键盘上的 Enter 键。
传输文件
最后,现在可以将文件传输到另一个 OneDrive 帐户。
您会看到,按下 Enter 键后,系统会要求您添加电子邮件帐户离职用户的用户名。
您还需要目标用户的用户名。这是文件将被复制和传输到的 OneDrive 用户。
最后,系统会要求您添加Office 365 管理员的用户名。
等待脚本执行其操作,然后再检查接收帐户以查看文件是否已正确传输。
复制并粘贴以下脚本:
$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
您可以在此 Reddit 页面上找到该脚本。
PowerShell 可以访问 OneDrive 吗?
SharePoint Online PowerShell 将使用户可以使用 PowerShell 工具连接到另一个 OneDrive 帐户。它会要求您输入密码,以便 PowerShell 开始通过 cmdlet 处理您的 OneDrive 帐户。
外部用户可以访问 OneDrive 吗?
外部用户可以访问您的 OneDrive 帐户,但前提是您允许。用户可以永久或在设定的时间段内访问您的文件。您还可以限制他们可以做的事情。
如何从别人的OneDrive复制文件?
如果您想要从他人的 OneDrive 复制文件,您可以选择以下选项:
使用链接在浏览器中打开 OneDrive,选择要复制的文件,然后单击“下载”。这会将其下载到您的计算机上。
使用链接打开 OneDrive 帐户,选择要复制的文件,然后单击“复制到”。
就是这样!
猜你还喜欢
- 03-30 [玩转系统] 如何用批处理实现关机,注销,重启和锁定计算机
- 02-14 [系统故障] Win10下报错:该文件没有与之关联的应用来执行该操作
- 01-07 [系统问题] Win10--解决锁屏后会断网的问题
- 01-02 [系统技巧] Windows系统如何关闭防火墙保姆式教程,超详细
- 12-15 [玩转系统] 如何在 Windows 10 和 11 上允许多个 RDP 会话
- 12-15 [玩转系统] 查找 Exchange/Microsoft 365 中不活动(未使用)的通讯组列表
- 12-15 [玩转系统] 如何在 Windows 上安装远程服务器管理工具 (RSAT)
- 12-15 [玩转系统] 如何在 Windows 上重置组策略设置
- 12-15 [玩转系统] 如何获取计算机上的本地管理员列表?
- 12-15 [玩转系统] 在 Visual Studio Code 中连接到 MS SQL Server 数据库
- 12-15 [玩转系统] 如何降级 Windows Server 版本或许可证
- 12-15 [玩转系统] 如何允许非管理员用户在 Windows 中启动/停止服务
取消回复欢迎 你 发表评论:
- 精品推荐!
-
- 最新文章
- 热门文章
- 热评文章
[影视] 黑道中人 Alto Knights(2025)剧情 犯罪 历史 电影
[古装剧] [七侠五义][全75集][WEB-MP4/76G][国语无字][1080P][焦恩俊经典]
[实用软件] 虚拟手机号 电话 验证码 注册
[电视剧] 安眠书店/你 第五季 You Season 5 (2025) 【全10集】
[电视剧] 棋士(2025) 4K 1080P【全22集】悬疑 犯罪 王宝强 陈明昊
[软件合集] 25年6月5日 精选软件22个
[软件合集] 25年6月4日 精选软件36个
[短剧] 2025年06月04日 精选+付费短剧推荐33部
[短剧] 2025年06月03日 精选+付费短剧推荐25部
[软件合集] 25年6月3日 精选软件44个
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电视剧] 欢乐颂.5部全 (2016-2024)
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[影视] 【稀有资源】香港老片 艺坛照妖镜之96应召名册 (1996)
[剧集] 神经风云(2023)(完结).4K
[剧集] [BT] [TVB] [黑夜彩虹(2003)] [全21集] [粤语中字] [TV-RMVB]
[实用软件] 虚拟手机号 电话 验证码 注册
[资源] B站充电视频合集,包含多位重量级up主,全是大佬真金白银买来的~【99GB】
[影视] 内地绝版高清录像带 [mpg]
[书籍] 古今奇书禁书三教九流资料大合集 猎奇必备珍藏资源PDF版 1.14G
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电影] 美国队长4 4K原盘REMUX 杜比视界 内封简繁英双语字幕 49G
[电影] 死神来了(1-6)大合集!
[软件合集] 25年05月13日 精选软件16个
[精品软件] 25年05月15日 精选软件18个
[绝版资源] 南与北 第1-2季 合集 North and South (1985) /美国/豆瓣: 8.8[1080P][中文字幕]
[软件] 25年05月14日 精选软件57个
[短剧] 2025年05月14日 精选+付费短剧推荐39部
[短剧] 2025年05月15日 精选+付费短剧推荐36部
- 最新评论
-
- 热门tag