Public/Sync-DTXCal.ps1
Function Sync-DTXCal { [CmdletBinding()] param( # # Parameter help description # [Parameter()] # [int] # $ProjectCode, # # Parameter help description # [Parameter()] # [Int] # $Month = [DateTime]::now.Month, # Parameter help description [Parameter(Mandatory)] [PSCustomObject[]] $CalEntry ) $Payloads = @{} # $CalEntry | % { Write-Verbose "Found $($PSItem.Month)" } Foreach($Entry in $CalEntry){ # $Entry.Month if(-not $Payloads[$Entry.Month]){ $Payloads.($Entry.Month) = @{} } if(-not $Payloads.($Entry.Month).($Entry.ProjectCode)){ $Payloads.($Entry.Month).($Entry.ProjectCode) = @() } $Payloads.($Entry.Month).($Entry.ProjectCode) += "day$($Entry.Day)=$($Entry.AllocatedTime)" } foreach($Payload in $Payloads){ #Month level foreach($month in $Payload.keys){ foreach($Project in $Payload.$month.keys){ try{ $null = New-DTXEntry -ProjectCode $Project -Month $month -DayEntry $Payload.$month.$Project }catch{ $false } } } } $true } |