Come trasferire file OneDrive a un altro utente tramite PowerShell

Come Trasferire File Onedrive A Un Altro Utente Tramite Powershell



Il trasferimento di file dal tuo account Microsoft OneDrive a un altro utente è facile, nel senso che puoi scaricare il contenuto dal tuo OneDrive, quindi caricarlo manualmente sull'altro account. In questo post, ti mostreremo come trasferire i file OneDrive a un altro utente tramite PowerShell .



  Come trasferire file OneDrive a un altro utente tramite PowerShell





Cose da considerare

Quando si tratta di caricare file dal tuo OneDrive su un altro account, è un'attività che richiederà del tempo perché al momento non è possibile caricare file di dimensioni superiori a 250 MB. La buona notizia è che PowerShell prenderà nota di tutti i file che non può caricare, quindi puoi cercarli e condividerli con il metodo normale.





Prima di caricare i file sull'altro account OneDrive, i file verranno prima scaricati sul tuo computer, quindi assicurati di avere spazio sufficiente sul tuo disco rigido o SSD prima di andare avanti. E poiché è necessaria la tua connessione Internet, la velocità complessiva del trasferimento dipenderà dalla qualità della rete.



Ora, dobbiamo notare che l'autenticazione a due fattori non esiste sull'account amministratore, quindi crea un account amministratore temporaneo che non abbia 2FA solo per questo scopo.

Cose di cui avrai bisogno

Useremo uno script speciale per spostare i file da un account OneDrive a un altro. Quindi, affinché lo script funzioni con problemi, installa subito i seguenti moduli PowerShell:

Modulo PowerShell PnP di SharePoint



Apri lo strumento PowerShell come amministratore, quindi esegui il seguente comando:

Install-Module SharePointPnPPowerShellOnline -Force

Shell di gestione di SharePoint Online

Lo scopo di questo strumento è modificare le autorizzazioni sull'account OneDrive degli utenti.

Scaricalo e installalo gratuitamente da microsoft.com .

Modulo MSOnline V1 PowerShell

Per installare questo modulo finale, esegui il seguente comando in PowerShell come amministratore:

Install-Module MSOnline -Force

Come trasferire i file OneDrive su un altro account

Per trasferire file dal tuo account OneDrive a un altro, devi aprire PowerShell e quindi eseguire lo script fornito.

megatrend americani tpm

Apri PowerShell

  Ricerca di Microsoft PowerShell

Apri Visual Studio Code o PowerShell.

Puoi farlo facendo clic sul pulsante Cerca, quindi cerca PowerShell.

Da lì, fai clic con il pulsante destro del mouse sull'app, quindi seleziona l'opzione progettata per aprire lo strumento in modalità amministratore.

Esegui lo script

  Script di OneDrive PowerShell

Successivamente, è necessario eseguire lo script pertinente. Lo trovate in fondo all'articolo.

Abbiamo scelto di farlo perché la sceneggiatura è piuttosto lunga.

Dopo aver aggiunto lo script, premi il tasto Invio sulla tastiera.

Trasferisci i file

Infine, è giunto il momento di trasferire i file su un altro account OneDrive.

Vedi, subito dopo aver premuto il tasto Invio, ti verrà chiesto di aggiungere l'account e-mail Il nome utente dell'utente uscente .

Avrai anche bisogno Il nome utente dell'utente di destinazione . Questo è l'utente di OneDrive in cui verranno copiati e trasferiti i file.

Infine, ti verrà chiesto di aggiungere Il nome utente dell'amministratore di Office 365 .

Attendi che lo script faccia il suo dovere prima di controllare l'account ricevente per vedere se i file sono stati trasferiti correttamente.

Copia e incolla lo script seguente:

$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

Puoi trovare lo script su questo Pagina reddit .

LEGGERE : Come esportare CSV in PowerShell su Windows

PowerShell può accedere a OneDrive?

SharePoint Online PowerShell consentirà agli utenti di connettersi a un altro account OneDrive utilizzando lo strumento PowerShell. Ti chiederà di inserire la tua password affinché PowerShell inizi a lavorare sui tuoi account OneDrive tramite cmdlet.

È possibile accedere a OneDrive da utenti esterni?

Gli utenti esterni possono accedere al tuo account OneDrive, ma solo se lo consenti. Gli utenti possono avere accesso ai tuoi file per sempre o per un determinato periodo di tempo. Puoi anche limitare ciò che possono fare.

Come copiare file da OneDrive di un'altra persona?

Hai le seguenti opzioni se vuoi copiare i file dal OneDrive di un'altra persona:

  • Apri OneDrive nel browser utilizzando il collegamento, seleziona i file che desideri copiare e fai clic su Download. Questo lo scaricherà sul tuo computer.
  • Apri l'account OneDrive utilizzando il collegamento, seleziona i file che desideri copiare e fai clic su Copia in.

Questo è tutto!

  Come trasferire file OneDrive a un altro utente tramite PowerShell
Messaggi Popolari