Last active
March 18, 2016 20:48
-
-
Save hanleybrand/e448e2bc8bdcf7d58c97 to your computer and use it in GitHub Desktop.
run via cmd-line with one course pk1 as a single argument, eg ` .\rubric_report.ps1 111220`
This file contains hidden or 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
| add-pssnapin sqlserverprovidersnapin100 | |
| add-pssnapin sqlservercmdletsnapin100 | |
| Function Remove-InvalidFileNameChars { | |
| param( | |
| [Parameter(Mandatory=$true, | |
| Position=0, | |
| ValueFromPipeline=$true, | |
| ValueFromPipelineByPropertyName=$true)] | |
| [String]$Name | |
| ) | |
| $invalidChars = [IO.Path]::GetInvalidFileNameChars() -join '' | |
| $re = "[{0}]" -f [RegEx]::Escape($invalidChars) | |
| return ($Name -replace $re) | |
| } | |
| # | |
| $cd = Get-Location | |
| $course_pk1 = $args[0] | |
| Write-Host "Generating Rubric reports for course pk1: $($course_pk1)" | |
| $RubricsReturned = @(Invoke-SQLCmd -Database bb_bb60 -Server localhost ` | |
| -query "exec SP_RUBRIC_LIST_FOR_COURSE_PK1 $course_pk1" ) | |
| <# Write-Host ($RubricsReturned | Format-Table | Out-String) #> | |
| ForEach ($row in $RubricsReturned) { | |
| $course_name = $row['COURSE_NAME'] | |
| $this_rubric = $row['rubric_pk1'] | |
| $rubric_title = $row['rubric_title'] | |
| $file_name = Remove-InvalidFileNameChars(("{0}_{1}" -f $course_name, $rubric_title)) | |
| Write-Host "Checking attempts for $this_rubric : $($row['rubric_title'])" | |
| $run_this = Invoke-Sqlcmd -Query "exec SP_RUBRIC_REPORT_COUNT_ATTEMPTS $($row['rubric_pk1'])" ` | |
| -Database bb_bb60 ` | |
| -Server localhost | |
| <# Write-Host ($run_this | Format-Table | Out-String) | |
| #> | |
| if ($run_this['group_attempts'] -ne 0) { | |
| Write-Host "$($run_this['group_attempts']) Group attempts -- Running Rubric Group report for $($row['rubric_title'])" | |
| Invoke-Sqlcmd -Query "exec SP_RUBRIC_REPORT_GROUPS_FOR_RUBRIC_PK1 $this_rubric" ` | |
| -Database bb_bb60 ` | |
| -Server localhost | | |
| Export-Csv -NoTypeInformation ` | |
| -Path "$cd\$($file_name)_group.csv" ` | |
| -Encoding UTF8 | |
| } | |
| else { Write-Host "$($run_this['group_attempts']) Group attempts... ignoring" } | |
| if ($run_this['indiv_attempts'] -ne 0) { | |
| Write-Host "$($run_this['indiv_attempts']) Individual attempts -- Running Rubric Group report for $($row['rubric_title'])" | |
| $this_report = Invoke-Sqlcmd -Query "exec SP_RUBRIC_REPORT_INDIV_FOR_RUBRIC_PK1 $this_rubric" ` | |
| -Database bb_bb60 ` | |
| -Server localhost | |
| <# Write-Host ($this_report | Format-Table | Out-String) #> | |
| $this_report | Export-Csv -NoTypeInformation ` | |
| -Path "$cd\$($file_name)_individual.csv" ` | |
| -Encoding UTF8 | |
| } | |
| else { Write-Host "$($run_this['indiv_attempts']) Individual attempts ... ignoring" } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment