Scheduling Dates

Tagged: 

This topic contains 0 replies, has 1 voice, and was last updated by  LAD 1 week, 2 days ago.

  • Author
    Posts
  • #79862

    LAD
    Participant

    I have a csv file that contains the following details
    samaccountname,extensionattribute5
    User01,22/09/2017
    User02,22/09/2017
    User03,22/09/2017
    User04,23/09/2017
    User05,23/09/2017
    User06,24/09/2017
    User07,24/09/2017
    User08,24/09/2017
    User09,25/09/2017
    User10,25/09/2017
    User11,
    User12,
    User13,

    I'm looking for the ability for the script to assign an available date (no earlier than a week) to those that don't have Extensionattribute5 populated.
    The day cannot have more than 3 users assigned

    The script needs to:
    Lists all the dates scheduled.
    Group them
    Checks if there are less than 3 users.
    If yes, then get the number of free slots, assign that date to the number of users.
    If no, find the next available date

    Remove-Variable *
    cls
    Set-Location $PSScriptRoot
    
     $1WeekAfterToday = (Get-date ).AddDays(8)
            If  ($1WeekAfterToday.DayOfWeek -eq 'Saturday')
                {
                "Scheduled date is Saturday adding one more day" | Write-Host -ForegroundColor Cyan
                $1WeekAfterToday = $1WeekAfterToday.AddDays('1') 
                }
            ElseIf ($1WeekAfterToday.DayOfWeek -eq 'Friday')
                {
                "Scheduled date is Friday scheduling for Sunday" | Write-Host -ForegroundColor Cyan
                $1WeekAfterToday = $1WeekAfterToday.AddDays('2')
                }
    $1WeekAfterToday = Get-Date $1WeekAfterToday -DisplayHint Date
    "Potential date is $($1WeekAfterToday.ToLongDateString())" | Write-Host -ForegroundColor Cyan
    
    #Get Users in Group
    $sourceUsers = Import-Csv .\sourceUsers.csv -Verbose
    
    Start-Sleep -Seconds 1 -Verbose
    #Get Users that are scheduled
    $PreScheduledUsers = Import-Csv .\sourceUsers.csv | Where-Object {$_.extensionattribute5 -ne ""} |
    Select-Object *,@{
        'Name' = 'SchedDate'
        'Expression' = { ([datetime]::ParseExact($_.extensionattribute5,"dd/MM/yyyy",[System.Globalization.CultureInfo]::InvariantCulture)) }
        } | 
        Sort SchedDate
    
    #Group Dates
    $AllDates =  $PreScheduledUsers | Group SchedDate 
    
    #Check if date is already in schedule
    
    #DO {
    Sleep 1
    #$Avail = 
    ForEach($datum in $AllDates)
        
        {    
            Write-Host "`r`n01. CHECKING $($1WeekAfterToday.ToShortDateString()) to $((Get-date $datum.Name).ToShortDateString())"
            If ($1WeekAfterToday.Date -eq (Get-date $datum.Name).Date ) 
                {
                Write-Host "`r`nFOUND A MATCH for $($1WeekAfterToday.Date)"
                IF ($datum.Count -lt 3)
                    {
                    Write-Host "LESS than 3"
                    (Get-date $datum.Name)
                    break
                    }
                ELSE
                    {
                    Write-Host "`r`nDATE NOt available less than ..checking next day"
                    $1WeekAfterToday = $1WeekAfterToday.AddDays(1)
                    continue
                    }#continue
               
                #Break
                }
               
            ELSE
                {
                Write-Host "`r`nNo MATCH for $($1WeekAfterToday.Date). Setting $1WeekAfterToday"
                $1WeekAfterToday
                #Break
                continue
                
                }
                #>
        }
        
      #  }
        #Until ($avail)
        $avail | Write-Host -ForegroundColor Yellow
    
    

You must be logged in to reply to this topic.