example-scripts/schedule-import-all-solutions.ps1



$content = Get-Content "..\.env"
$content | ForEach-Object {
  $str = $_.split("=")
  New-Variable -Name $str[0] -Value $str[1] -Force
}
# Enter-PSSession -ComputerName $computername


$conn = Get-RegentConnection -CrmInstance CRMRECRUIT

$publisher = Get-CrmRecords -EntityLogicalName publisher -conn $conn -fields * -FilterAttribute friendlyname -FilterOperator eq -FilterValue "Regent Ops"

$sols = Get-CrmRecords -EntityLogicalName "solution" -conn $conn -Fields uniquename, description, publisherid -FilterAttribute publisherid -FilterOperator eq -FilterValue $publisher.CrmRecords[0].publisherid

Write-Host -ForegroundColor green "Located the following solutions"
$sols.CrmRecords | ForEach-Object {
  Write-Host $_.uniquename
}

Write-host "All the above solutions wil lbe imported into CRMRECRUITDEV. Are you sure you want to continue?" -ForegroundColor Yellow 
$Readhost = Read-Host "Select Y or N (default N) " 
Switch ($ReadHost) {
  Y { $continue = $true} 
  N { $continue = $false} 
  Default { $continue = $false } 
}
if (-not $continue) {
  Write-Host "Canceling operation."
  return
}

$time = Get-Date "11:15PM"
$sols.CrmRecords | ForEach-Object {
  $time.AddMinutes(15)
  Write-Host $_
  Move-RegentSolution -SolutionName $_.uniquename`
    -SourceCrmInstance CRMRECRUIT `
    -DestinationCrmInstance CRMRECRUITTEST `
    -Managed $false `
    -PublishCustomizations $false `
    -Emails "dhines@regent.edu" `
    -CommitMessage "Added $($_.uniquename)" `
    -ImportTime $time `
    -Verbose
}

# Exit-PSSession