Param Parameter Mandatory true Position HelpMessage Your domain user n

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Param(
[Parameter(Mandatory=$true, Position=0, HelpMessage="Your domain user name (without domain name).")]
[string]$username,
[Parameter(Mandatory=$true, Position=1, HelpMessage="Your domain account password.")]
[SecureString]$password
)
function UnixTimeStampToDateTime([long]$unixTimeStamp)
{
$UnixEpoch = New-Object DateTime @(1970, 1, 1, 0, 0, 0, 0, "Utc")
return $UnixEpoch.AddMilliseconds($unixTimeStamp).ToLocalTime()
}
$me = $username
$pass = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))
Invoke-RestMethod `
-Uri "http://youtrack.crossmarket.across.lan/rest/user/login" `
-Body @{login="acrosssys\$me"; password=$pass} `
-Method Post `
-SessionVariable sess `
-ErrorAction Stop | Out-Null
if(-not $?) {
throw "Could not login."
}
$ticketsResponse = Invoke-RestMethod `
-Uri "http://youtrack.crossmarket.across.lan/rest/issue?filter=for+%23me+updated%3A+Today" `
-Method Get `
-WebSession $sess
$ids = $tickets.issueCompacts.issue.id
$allWorkItems = $ids `
| % { Invoke-RestMethod -Uri "http://youtrack.crossmarket.across.lan/rest/issue/$_/timetracking/workitem" -Method Get -WebSession $sess } `
| %{$_.workitems.workitem}
$myWorkItems = @( $allWorkItems |? {$_.author.login -eq $me -and (UnixTimeStampToDateTime $_.date).Date -eq [DateTime]::Today} )
$totalDuration = ($myWorkItems.duration | measure -Sum).Sum
[timespan]::FromMinutes( $totalDuration ).ToString()