Merge branch 'main' of https://git.steelants.cz/kotlanj/ps_shiftplan
This commit is contained in:
64
shifts.ps1
64
shifts.ps1
@@ -44,27 +44,27 @@ function Set-Shift {
|
||||
[string]$mail
|
||||
)
|
||||
|
||||
#$params = @{
|
||||
# UserId = $userId
|
||||
# schedulingGroupId = $groupID
|
||||
# sharedShift = @{
|
||||
# notes = ($shiftName)
|
||||
# startDateTime = [System.DateTime]::Parse($StartDate.ToString("yyyy-MM-dd'T'HH:mm:ssZ"))
|
||||
# endDateTime = [System.DateTime]::Parse($EndDate.ToString("yyyy-MM-dd'T'HH:mm:ssZ"))
|
||||
# theme = $color
|
||||
# }
|
||||
#}
|
||||
$params = @{
|
||||
UserId = $userId
|
||||
schedulingGroupId = $groupID
|
||||
sharedShift = @{
|
||||
notes = ($shiftName)
|
||||
startDateTime = [System.DateTime]::Parse($StartDate.ToString("yyyy-MM-dd'T'HH:mm:ssZ"))
|
||||
endDateTime = [System.DateTime]::Parse($EndDate.ToString("yyyy-MM-dd'T'HH:mm:ssZ"))
|
||||
theme = $color
|
||||
}
|
||||
}
|
||||
|
||||
#$headers = @{
|
||||
# "MS-APP-ACTS-AS" = $userIdAdmin
|
||||
# "Prefer" = "no-notification"
|
||||
#}
|
||||
|
||||
#$newShift = New-MgTeamScheduleShift -TeamId $teamID -DraftShift -BodyParameter $params -Headers @{ "MS-APP-ACTS-AS" = $userIdAdmin }
|
||||
$newShift = New-MgTeamScheduleShift -TeamId $teamID -BodyParameter $params -Headers @{ "MS-APP-ACTS-AS" = $userIdAdmin }
|
||||
#Write-Debug ("SCHEDULING: {0} {1} - {2}" -f $newShift.SharedShift.StartDateTime.ToString("yyyy-MM-dd HH:mm"), $newShift.SharedShift.EndDateTime.ToString("yyyy-MM-dd HH:mm"), $newShift.SharedShift.Notes)
|
||||
#("SCHEDULING: {0} {1} - {2}" -f $newShift.SharedShift.StartDateTime.ToString("yyyy-MM-dd HH:mm"), $newShift.SharedShift.EndDateTime.ToString("yyyy-MM-dd HH:mm"), $newShift.SharedShift.Notes) | Add-Content -Path $logPath
|
||||
Write-Debug("{0} {1}: {2} {3}" -f $dayDate, $dayDate.DayOfWeek, $mail, $shiftName)
|
||||
$newShift = 0
|
||||
Write-Debug("{0} {1}: {2} {3} {4} {5}" -f $dayDate, $dayDate.DayOfWeek, $mail, $shiftName, $StartDate, $EndDate)
|
||||
#$newShift = 0
|
||||
return $newShift
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ Connect-MgGraph -AccessToken $($token | ConvertTo-SecureString -AsPlainText -For
|
||||
|
||||
#$today = (Get-Date).Date
|
||||
#$today = $today_old.AddYears(2)
|
||||
$today = Get-Date -Day 11 -Month 1 -Year 2027 -Hour 9 -Minute 00 -Second 00 -Millisecond 00
|
||||
$today = Get-Date -Day 1 -Month 2 -Year 2027 -Hour 9 -Minute 00 -Second 00 -Millisecond 00
|
||||
|
||||
$schedule = Get-Content -Path "./config.json" -Raw | ConvertFrom-Json
|
||||
|
||||
@@ -167,7 +167,7 @@ $allemails = $schedule.PSObject.Properties | ForEach-Object {
|
||||
|
||||
#$Monday = $today.AddDays(1 - $today.DayOfWeek.value__)
|
||||
#$Friday = $Monday.AddDays(4)
|
||||
$daysahead = 14
|
||||
$daysahead = 5
|
||||
|
||||
$startSpanDate = Get-Date -Day $today.Day -Month $today.Month -Year $today.Year -Hour 9 -Minute 00 -Second 00 -Millisecond 00
|
||||
$endSpanDate = Get-Date -Day $startSpanDate.AddDays($daysahead).Day -Month $startSpanDate.AddDays($daysahead).Month -Year $startSpanDate.AddDays($daysahead).Year -Hour 17 -Minute 00 -Second 00 -Millisecond 00
|
||||
@@ -226,11 +226,9 @@ try {
|
||||
$dateStart = $(get-date -Day $dayDate.Day -Month $dayDate.Month -Year $dayDate.Year -Hour 9 -Minute 00 -Second 00).AddHours(-1)
|
||||
$dateEnd = $(get-date -Day $dayDate.Day -Month $dayDate.Month -Year $dayDate.Year -Hour 17 -Minute 00 -Second 00).AddHours(-1)
|
||||
|
||||
if (($dayDate.IsDaylightSavingTime()) -eq $false) {
|
||||
if (($dayDate.IsDaylightSavingTime()) -eq $true) {
|
||||
$dateStart = $dateStart.AddHours(-1)
|
||||
$dateEnd = $dateStart.AddHours(-1)
|
||||
}
|
||||
else {
|
||||
$dateEnd = $dateEnd.AddHours(-1)
|
||||
}
|
||||
|
||||
$shifts_today = [Object[]] $allshifts | Where-Object -Filter {
|
||||
@@ -326,7 +324,7 @@ try {
|
||||
foreach ($shift in $shifts_today) {
|
||||
if($shift.UserId -eq $futureds_id) {
|
||||
Write-Debug(">>> {0} {1}: removing shift {2} {3} {4} for {5}" -f $futureday, $futureday.DayOfWeek, $shift.Notes, $shift.StartDateTime, $shift.EndDateTime, $futureds_email)
|
||||
#Remove-MgTeamScheduleShift -ShiftId $shift.id -TeamId $team.Id
|
||||
Remove-MgTeamScheduleShift -ShiftId $shift.id -TeamId $team.Id
|
||||
if($futureds_email -in $ho_emails) {
|
||||
$newshift = Set-Shift -userId $futureds_id -groupID $group.id -shiftName "Home Office - Denní směna" -StartDate $dateStart -EndDate $dateEnd -color "purple" -teamID $team.id -mail $futureds_email
|
||||
$allshifts += [Object[]] $newshift
|
||||
@@ -360,6 +358,7 @@ try {
|
||||
}
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -379,16 +378,9 @@ try {
|
||||
if($email -eq $rlcz_mtnc_email) {
|
||||
if ($dayDate.DayOfWeek -eq "Thursday") {
|
||||
$yesterday = $dayDate.AddDays(-1)
|
||||
if (($yesterday.IsDaylightSavingTime()) -eq $false) {
|
||||
$rlcz_shift_start = $(get-date -Day $yesterday.Day -Month $yesterday.Month -Year $yesterday.Year -Hour 18 -Minute 00 -Second 00).AddHours(-1)
|
||||
$rlcz_shift_end = $(get-date -Day $yesterday.Day -Month $yesterday.Month -Year $yesterday.Year -Hour 23 -Minute 00 -Second 00).AddHours(-1)
|
||||
}
|
||||
else {
|
||||
$rlcz_shift_start = $(get-date -Day $yesterday.Day -Month $yesterday.Month -Year $yesterday.Year -Hour 18 -Minute 00 -Second 00).AddHours(-2)
|
||||
$rlcz_shift_end = $(get-date -Day $yesterday.Day -Month $yesterday.Month -Year $yesterday.Year -Hour 23 -Minute 00 -Second 00).AddHours(-2)
|
||||
}
|
||||
$rlcz_shifts = [Object[]] $allshifts | Where-Object -Filter { $_.schedulingGroupId -eq $group.Id -and $_.SharedShift.Notes -eq "RLCZ" -and $_.SharedShift.StartDateTime.ToString("yyyy-MM-dd HH:mm") -ge $rlcz_shift_start.ToString("yyyy-MM-dd HH:mm") -and $_.SharedShift.EndDateTime.ToString("yyyy-MM-dd HH:mm") -le $rlcz_shift_end.ToString("yyyy-MM-dd HH:mm") }
|
||||
if (Invoke-HasShift -UID $userId -shifts $rlcz_shifts -eq $true -mail $email) {
|
||||
$rlcz_shifts = [Object[]] $allshifts | Where-Object -Filter { $_.schedulingGroupId -eq $group.Id -and $_.SharedShift.Notes -eq "RLCZ" -and ($_.SharedShift.StartDateTime.Date -eq $yesterday.Date -or $_.SharedShift.EndDateTime.Date -eq $yesterday.Date) }
|
||||
|
||||
if (Invoke-HasShift -UID $userId -shifts $rlcz_shifts -mail $email) {
|
||||
if((Invoke-HasShiftorTimeOff -UID $userId -shifts $shifts_today -timeoff $timeoff_toda -mail $email) -eq $false) {
|
||||
if($email -in $ho_emails) {
|
||||
$newshift = Set-Shift -userId $userId -groupID $group.id -shiftName "Home office" -StartDate $dateStart -EndDate $dateEnd.AddHours($rlcz_shift_reduction) -color "pink" -teamID $team.id -mail $email
|
||||
@@ -413,6 +405,8 @@ try {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if((Invoke-HasShiftorTimeOff -UID $userId -shifts $shifts_today -timeoff $timeoff_today -mail $email) -eq $false) {
|
||||
$newshift = Set-Shift -userId $userId -groupID $group.id -shiftName "Office" -StartDate $dateStart -EndDate $dateEnd -color "blue" -teamID $team.id -mail $email
|
||||
$allshifts += [Object[]] $newshift
|
||||
@@ -421,6 +415,16 @@ try {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$params = @{
|
||||
notifyTeam = $false
|
||||
startDateTime = [System.DateTime]::Parse($startSpanDate.ToString("yyyy-MM-dd'T'HH:mm:ssZ"))
|
||||
endDateTime = [System.DateTime]::Parse($endSpanDate.ToString("yyyy-MM-dd'T'HH:mm:ssZ"))
|
||||
}
|
||||
|
||||
Invoke-MgShareTeamSchedule -TeamId $team.Id -BodyParameter $params -Headers @{ "MS-APP-ACTS-AS" = $userIdAdmin }
|
||||
("SHARING: {0}" -f $scheduleGroupName) | Add-Content -Path $logPath
|
||||
|
||||
}
|
||||
catch {
|
||||
$_
|
||||
|
Reference in New Issue
Block a user