Created
May 29, 2018 02:05
-
-
Save VibhuKuchhal/1eb2df11c792d12d2509c98fdabca8af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$credentials = 'D:\codes\AutomationScripts\GetCredentials.ps1' | |
$migrationDataFolder = '\\masterterminal\c$\AutomatedMigrationData' | |
$packagesFolder = 'packages' | |
$mailFolder = 'mails' | |
$reportsFolder = 'reports' | |
$inputFolder = 'input' | |
$processingFolder = 'processing' | |
$finalFolder = 'final' | |
$migrationConfigSiteUrl = 'https://yourtenant.sharepoint.com/sites/HSSPilot' | |
$migrationConfigList = 'Migrationsconfig' | |
function Download-MigrationItem { | |
Param( | |
[string] $sourcePath, | |
[String] $destinationSite, | |
[String] $destinationlibrary, | |
[string] $id | |
) | |
$path = $migrationDataFolder + '\' + $packagesFolder + '\' + $inputFolder + '\' + (Get-Date).ToString("yyyyMMdd-hhmmss") + "_" + $id + "_" + $destinationlibrary + ".csv" | |
$props = @{ | |
Id = $Id | |
source = $sourcePath | |
destinationSite = $destinationSite | |
destinationlibrary = $destinationlibrary | |
} | |
$object = new-object psobject -Property $props | |
# Write migration data as a packet | |
$object | Export-Csv -Path $path -NoTypeInformation | |
} | |
Function Check-MigrationItems{ | |
Connect-PnPOnline -Url $migrationConfigSiteUrl -Credentials $credentials | |
$itemIds = (Get-PnPListItem -List $migrationConfigList -PageSize 1 -Query "<View><Query><Where><And><And><Eq><FieldRef Name='ReadyToMigrate'/><Value Type='Integer'>1</Value></Eq><Eq><FieldRef Name='Started'/><Value Type='Integer'>0</Value></Eq></And><Eq><FieldRef Name='Migrated'/><Value Type='Integer'>0</Value></Eq></And></Where></Query></View>").Id | |
#$itemIds | |
if($itemIds) | |
{ | |
foreach($itemid in $itemIds) | |
{ | |
#Get Item from the List | |
$item = (Get-PnPListItem -List "MigrationList" -Id $itemid -Fields "Id","Source","DestinationSite","DestinationLibrary","TerminalName","MigrateAllData").fieldvalues | |
#$item | |
#Download migration data as a Csv | |
Download-MigrationItem -id $itemid -sourcePath $item.Source -destinationSite $item.DestinationSite -destinationlibrary $item.DestinationLibrary | |
#Set Item processing as started | |
Set-PnPListItem -List "MigrationList" -Identity $itemid -Values @{"Started" = $true;} | |
} | |
} | |
else | |
{ | |
write-host "No migration items available. Sleeping for 1 Minute." | |
Start-Sleep -Seconds 30 | |
} | |
} | |
while($true) | |
{ | |
Check-MigrationItems | |
write-host "No migration items available. Sleeping for 30 Minutes." | |
Start-Sleep -Seconds 1800 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment