Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $DBServer="DBServ"
- $DB="DB"
- $Query_SQL="SELECT courseCode + staLName + CAST((FORMAT(schDateStart, 'yyyyMMdd')) AS VARCHAR) + rooRoom as PK,
- couTitle + '-' + SchSectionID + '-' + staLName + ' ' + CAST((FORMAT(schDateStart, 'yyyyMMdd')) AS VARCHAR) AS ID,
- couTitle AS CourseTitle,
- courseCode AS CourseCode,
- schSectionID AS SecID,
- schDateStart AS DateStart,
- schDateEnd AS DateEnd,
- schTimeStart AS TimeStart,
- schTimeEnd AS TimeEnd,
- schDaysOfWeek AS Days,
- schCourseStatus AS Status,
- schNotes AS Notes,
- rooRoom AS RoomNumber,
- facName AS Facility,
- staFName + ' ' + staLName AS Instructor,
- lastModified AS LastModified ,
- CustomSchedule AS Custom
- FROM VIEW
- ORDER BY schDateStart"
- $conn_SQL=New-Object system.data.sqlclient.sqlconnection("Server=$DBServer;Database=$DB;Integrated Security=True")
- $da_SQL=New-Object system.data.sqlclient.sqldataadapter($Query_SQL,$conn_SQL)
- $dt_SQL=New-Object system.data.datatable
- #try the SQL connection if error then exit the script
- try
- {
- $conn_SQL.Open()
- [void]$da_SQL.fill($dt_SQL)
- $conn_SQL.Close()
- }
- catch
- {
- Write-Output "Error connecting to DB"
- exit
- }
- $dt_SQL.primarykey=$dt_SQL.columns[0]
- $Sections=$dt_SQL.Rows
- foreach($section in $Sections | Where-Object {$_.Custom -eq "true"})
- {
- if(($Sections | Where-Object {$_.secID -eq $section.SecID}).count -gt 1)
- {
- foreach($sec in $Sections | Where-Object {$_.secID -eq $section.SecID})
- {
- if($sec.LastModified -gt $lastUpdate)
- {
- foreach($sect in $Sections | Where-Object {$_.secID -eq $section.SecID})
- {
- $sect.LastModified = $sec.LastModified
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment