Functions/Get-WorkingTime.ps1



function Get-WorkingTime {

    # version 1


    # $Date = Get-Date

    # $Today = [string]$Date.Day + [string]$Date.Month + [string]$Date.Year

    #$ComputerinfoTempFile =

    # $ComputerinfoTempFile = "$($env:TEMP)\ComputerInfo_$($Today).csv"

    # if (!(Test-Path $ComputerinfoTempFile)) {
    # Get-ComputerInfo | Export-Csv -Path $ComputerinfoTempFile -NoTypeInformation
    # }

    $WT = [ordered]@{}

    # $Computerinfo = Import-Csv $ComputerinfoTempFile

    # $OsLastBootUpTime = Get-Date -Date $Computerinfo.OsLastBootUpTime

    $WTFolderPath = "C:\temp\WorkingTime"
    if(-not(Test-Path $WTFolderPath)) {
        New-Item $WTFolderPath -ItemType Directory -Force | Out-Null
    }
    $WTFilePath = Join-Path $WTFolderPath "wt_$(Get-Date -Format "yyyy-MM-dd").json"
    # Remove-Item $WTFilePath -Force -ea 0
    if (Test-Path $WTFilePath) {
        $WTInfo = Get-Content $WTFilePath | ConvertFrom-Json
        $WMI_OsLastBootUpTime = $WTInfo.LastBootUpTime
    } else {
        # $WMI_OsLastBootUpTime = Get-CimInstance win32_operatingsystem | Select-Object @{LABEL = 'LastBootUpTime'; EXPRESSION = { ($_.ConverttoDateTime($_.lastbootuptime)).DateTime } }
        $WMI_OsLastBootUpTime = Get-CimInstance win32_operatingsystem | Select-Object LastBootUpTime
        $WMI_OsLastBootUpTime | ConvertTo-Json | Out-File $WTFilePath
        $WMI_OsLastBootUpTime = $WMI_OsLastBootUpTime.LastBootUpTime
    }
    # $WMI_OsLastBootUpTime


    $OsLastBootUpTime = Get-Date $WMI_OsLastBootUpTime

    $WT["StartTijd"] = Get-Date $OsLastBootUpTime -Format "HH:mm:ss"

    $WorkingTime = (Get-Date) - $OsLastBootUpTime

    $WT["TijdGewerkt"] = $WorkingTime


    $HoeLangNog = (Get-Date -Hour 8 -Minute 30 -Second 0) - $WorkingTime

    $WT["HoeLangNog"] = Get-Date $HoeLangNog -Format "HH:mm:ss"

    $HoeLangNogHalveDag = (Get-Date -Hour 4 -Minute 0 -Second 0) - $WorkingTime

    $WT["HoeLangNogHalveDag"] = Get-Date $HoeLangNogHalveDag -Format "HH:mm:ss"

    $WT["JeMoetTot"] = Get-Date $OsLastBootUpTime.AddMinutes(510) -Format "HH:mm:ss"

    return $WT

}