Skip to content

Instantly share code, notes, and snippets.

@Ryan2065
Last active August 10, 2020 21:47
Show Gist options
  • Save Ryan2065/436d851fc2d45d3804db7ca0d2057fa3 to your computer and use it in GitHub Desktop.
Save Ryan2065/436d851fc2d45d3804db7ca0d2057fa3 to your computer and use it in GitHub Desktop.
Job Tracker using EFPosh PowerShell Module
Function Start-CollectionMigration {
Param($Collection)
Start-Sleep -Milliseconds 250
}
Function Test-CollectionMigration {
Param($Collection)
$Random = Get-Random -Minimum 1 -Maximum 10
if($Random -eq 2){
return $false
}
return $true
}
Function Get-CollectionsToMigrate {
10..99 | foreach-object { @{ 'CollectionId' = "PS1000$($_)" } }
}
Class JobTracker {
[string]$CollectionId
[bool]$Complete
}
$Tables = @( New-EFPoshEntityDefinition -Type 'JobTracker' -PrimaryKeys 'CollectionId' )
$Context = New-EFPoshContext -SQLiteFile '.\JobTracker.sqlite' -Entities $Tables -EnsureCreated
$CollectionsToMigrate = Get-CollectionsToMigrate
Foreach($Collection in $CollectionsToMigrate) {
$Record = Search-EFPosh -Entity $Context.JobTracker -Expression { $_.CollectionId -eq $Collection.CollectionId } -FirstOrDefault
if($null -eq $Record){
$Record = [JobTracker]::new()
$Record.CollectionId = $Collection.CollectionId
$Context.Add($Record)
$Context.SaveChanges()
}
if($false -eq $Record.Complete){
Write-Host "Migrating $($Collection.CollectionId)"
Start-CollectionMigration -Collection $Collection
$Record.Complete = Test-CollectionMigration -Collection $Collection
$Context.SaveChanges()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment