วิธีถ่ายโอนไฟล์ OneDrive ไปยังผู้ใช้รายอื่นผ่าน PowerShell

Withi Thay Xon Fil Onedrive Pi Yang Phu Chi Ray Xun Phan Powershell



การถ่ายโอนไฟล์จากบัญชี Microsoft OneDrive ของคุณไปยังผู้ใช้รายอื่นทำได้ง่าย โดยคุณสามารถดาวน์โหลดเนื้อหาจาก OneDrive ของคุณ แล้วอัปโหลดไปยังบัญชีอื่นด้วยตนเอง ในโพสต์นี้ เราจะแสดงวิธีการ ถ่ายโอนไฟล์ OneDrive ไปยังผู้ใช้รายอื่นผ่าน PowerShell .



  วิธีถ่ายโอนไฟล์ OneDrive ไปยังผู้ใช้รายอื่นผ่าน PowerShell





สิ่งที่ต้องพิจารณา

เมื่อพูดถึงการอัปโหลดไฟล์จาก OneDrive ของคุณไปยังบัญชีอื่น จะเป็นงานที่ต้องใช้เวลาสักระยะหนึ่ง เนื่องจากไม่สามารถอัปโหลดไฟล์ที่มีขนาดใหญ่กว่า 250MB ได้ในขณะนี้ ข่าวดีก็คือ PowerShell จะจดบันทึกไฟล์ทั้งหมดที่ไม่สามารถอัปโหลดได้ ดังนั้นคุณจึงสามารถค้นหาและแชร์ไฟล์เหล่านี้ได้ด้วยวิธีปกติ





ก่อนที่จะอัปโหลดไฟล์ไปยังบัญชี OneDrive อื่น ไฟล์จะถูกดาวน์โหลดไปยังคอมพิวเตอร์ของคุณก่อน ดังนั้น ตรวจสอบให้แน่ใจว่าคุณมีพื้นที่ว่างเพียงพอในฮาร์ดไดรฟ์หรือ SSD ก่อนที่จะดำเนินการต่อ และเนื่องจากจำเป็นต้องมีการเชื่อมต่ออินเทอร์เน็ต ความเร็วโดยรวมของการถ่ายโอนจะขึ้นอยู่กับคุณภาพของเครือข่าย



ตอนนี้ เราต้องทราบว่าการตรวจสอบสิทธิ์แบบสองปัจจัยไม่มีอยู่ในบัญชีผู้ดูแลระบบ ดังนั้นให้สร้างบัญชีผู้ดูแลระบบชั่วคราวที่ไม่มี 2FA เพื่อจุดประสงค์นี้เท่านั้น

สิ่งที่คุณต้องการ

เราจะใช้สคริปต์พิเศษเพื่อย้ายไฟล์จากบัญชี OneDrive หนึ่งไปยังอีกบัญชีหนึ่ง ดังนั้น เพื่อให้สคริปต์ทำงานกับปัญหาได้ โปรดติดตั้งโมดูล PowerShell ต่อไปนี้ทันที:

โมดูล SharePoint PnP PowerShell



เปิดเครื่องมือ PowerShell ในฐานะผู้ดูแลระบบ จากนั้นเรียกใช้คำสั่งต่อไปนี้:

วิธีลบ internet explorer ออกจาก windows 7 อย่างสมบูรณ์
Install-Module SharePointPnPPowerShellOnline -Force

เชลล์การจัดการออนไลน์ของ SharePoint

วัตถุประสงค์ของเครื่องมือนี้คือเพื่อแก้ไขสิทธิ์ในบัญชี OneDrive ของผู้ใช้

ดาวน์โหลดและติดตั้งได้ฟรีจาก ไมโครซอฟท์.คอม .

โมดูล MSOnline V1 Powershell

ในการติดตั้งโมดูลสุดท้ายนี้ โปรดเรียกใช้คำสั่งต่อไปนี้ใน PowerShell ในฐานะผู้ดูแลระบบ:

Install-Module MSOnline -Force

วิธีโอนไฟล์ OneDrive ไปยังบัญชีอื่น

ในการถ่ายโอนไฟล์จากบัญชี OneDrive ของคุณไปยังบัญชีอื่น คุณต้องเปิด PowerShell แล้วเรียกใช้สคริปต์ที่มีให้

เปิด PowerShell

  การค้นหา Microsoft PowerShell

windows แจ้งเตือนแบตเตอรี่ต่ำ 10

เปิด Visual Studio Code หรือ PowerShell

คุณสามารถทำได้โดยคลิกที่ปุ่มค้นหา จากนั้นค้นหา PowerShell

จากนั้น คลิกขวาที่แอป จากนั้นเลือกตัวเลือกที่ออกแบบมาเพื่อเปิดเครื่องมือในโหมดผู้ดูแลระบบ

เรียกใช้สคริปต์

  สคริปต์ OneDrive 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

คุณสามารถค้นหาสคริปต์นี้ หน้าเรดดิท .

อ่าน : วิธีส่งออก CSV ใน PowerShell บน Windows

PowerShell สามารถเข้าถึง OneDrive ได้หรือไม่

SharePoint Online PowerShell จะทำให้ผู้ใช้สามารถเชื่อมต่อกับบัญชี OneDrive อื่นได้โดยใช้เครื่องมือ PowerShell ระบบจะขอให้คุณใส่รหัสผ่านเพื่อให้ PowerShell เริ่มทำงานในบัญชี OneDrive ของคุณโดยใช้ cmdlets

macrium สะท้อนรีวิวฟรี

ผู้ใช้ภายนอกสามารถเข้าถึง OneDrive ได้หรือไม่

บัญชี OneDrive ของคุณสามารถเข้าถึงได้โดยผู้ใช้ภายนอก แต่ถ้าคุณอนุญาตเท่านั้น ผู้ใช้สามารถเข้าถึงไฟล์ของคุณได้ตลอดไปหรือตามระยะเวลาที่กำหนด คุณยังสามารถจำกัดสิ่งที่พวกเขาทำได้

วิธีคัดลอกไฟล์จาก OneDrive ของบุคคลอื่น

คุณมีตัวเลือกต่อไปนี้ถ้าคุณต้องการคัดลอกไฟล์จาก OneDrive ของบุคคลอื่น:

  • เปิด OneDrive ในเบราว์เซอร์ของคุณโดยใช้ลิงก์ เลือกไฟล์ที่คุณต้องการคัดลอกแล้วคลิกดาวน์โหลด นี่จะดาวน์โหลดลงในคอมพิวเตอร์ของคุณ
  • เปิดบัญชี OneDrive โดยใช้ลิงก์ เลือกไฟล์ที่คุณต้องการคัดลอก แล้วคลิก คัดลอกไปยัง

แค่นั้นแหละ!

  วิธีถ่ายโอนไฟล์ OneDrive ไปยังผู้ใช้รายอื่นผ่าน PowerShell
โพสต์ยอดนิยม