personio/functions/personio.ps1
2024-07-26 19:37:06 +02:00

133 lines
5.1 KiB
PowerShell

Function Get-Token
{
$creds = @{
client_id=$username
client_secret=$password
};
try
{
$response = Invoke-RestMethod "$application/v1/auth" -Method Post -Body $creds;
#Write-Host "$response"
$token = $response.data;
return $token;
}
catch
{
$result = $_.Exception.Response.GetResponseStream();
$reader = New-Object System.IO.StreamReader($result);
#Write-Host $($response)
$reader.BaseStream.Position = 0;
$reader.DiscardBufferedData();
$responseBody = $reader.ReadToEnd() | ConvertFrom-Json
Write-Host "ERROR: $($responseBody.errorCode) - $($responseBody.message)"
return;
}
}
Function GET-ExchangeSubject($VacationType = "") {
if ($VacationType -eq "57659"){
$Response=@{Name="Mutterschutz"; Status="Busy"}
}elseif ($VacationType -eq "37147") {
$Response=@{Name="Elternzeit"; Status="Busy"}
}elseif ($VacationType -eq "46191" -or $VacationType -eq "37135" -or $VacationType -eq "46188") {
$Response=@{Name="Urlaub"; Status="Busy"}
}elseif ($VacationType -eq "48771") {
$Response=@{Name="Homeoffice"; Status="Free"}
}elseif ($VacationType -eq "48780") {
$Response=@{Name="Dienstreise"; Status="Busy"}
}elseif ($VacationType -eq "37138" -or $VacationType -eq "44790" -or $VacationType -eq "48777" -or $VacationType -eq "48774") {
$Response=@{Name="Abwesend"; Status="Busy"}
}elseif ($VacationType -eq "44787") {
$Response=@{Name="Berufsschule"; Status="Busy"}
}elseif ($VacationType -eq "48825") {
$Response=@{Name="Weiterbildung"; Status="Busy"}
}else{
$Response=@{Name="Abwesend"; Status="Busy"}
}
Return $RESPONSE
}
Function Get-UserInfo
{
$Request = [System.UriBuilder]"$application/v1/company/employees"
# Setze TOKEN Header
$PERSONIO_TOKEN = Get-Token
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer $($PERSONIO_TOKEN.token)")
$GetUserResult = Invoke-WebRequest -UseBasicParsing -Uri $Request.Uri -Method GET -Headers $headers -ContentType "application/json"
Return $GetUserResult
}
Function Get-UserPicture{
[CmdletBinding()]
param(
[Parameter(Position = 1, Mandatory = $true)]
$PersonioID
)
Begin {
Write-Verbose "Get-UserPicture"
}
Process {
try {
$Request = [System.UriBuilder]"$application/v1/company/employees/$($PersonioID)/profile-picture/200"
# Setze TOKEN Header
$PERSONIO_TOKEN = Get-Token
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer $($PERSONIO_TOKEN.token)")
$headers.Add("accept", "image/png")
#Invoke-WebRequest -UseBasicParsing -Verbose -Debug -Uri $Request.Uri -Method GET -Headers $headers -ContentType "image/png" -OutFile "C:\testbild.jpg" | Select-Object *
$test = Invoke-WebRequest -UseBasicParsing -Uri $Request.Uri -Method GET -Headers $headers # -ContentType "image/png"
Return $test
}
catch {
Write-Log -Message "Error: $($_.Exception.Message) - Line Number: $($_.InvocationInfo.ScriptLineNumber)" -Level Error
Return $false
}
}
End {
Write-Verbose "Stop Get-UserPicture"
}
}
Function Get-UserVacation()
{
$STARTDATE="$((Get-Date).AddDays(-30).ToString('yyyy-MM-dd'))"
$DIFFDATE="$((Get-Date).AddDays(-1).ToString('yyyy-MM-dd'))"
$Request = [System.UriBuilder]"$application/v1/company/time-offs?start_date=$STARTDATE"
#$Requestoffset = [System.UriBuilder]"$application/v1/company/time-offs?start_date=$STARTDATE"
# Setze TOKEN Header
$PERSONIO_TOKEN = Get-Token
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer $($PERSONIO_TOKEN.token)")
#$GetVacationResult2 = Invoke-WebRequest -UseBasicParsing -Uri $Requestoffset.Uri -Method GET -Headers $headers -ContentType "application/json"
#$json = $GetVacationResult2 | ConvertFrom-Json
#$json
#($json.psobject.properties.Value).total_pages
#exit
$GetVacationResult = Invoke-WebRequest -UseBasicParsing -Uri $Request.Uri -Method GET -Headers $headers -ContentType "application/json"
Return $GetVacationResult
}
Function Get-DIFFUserVacation()
{
$STARTDATE="$((Get-Date).AddDays(-30).ToString('yyyy-MM-dd'))"
$DIFFDATE="$((Get-Date).AddDays(-1).ToString('yyyy-MM-dd'))"
$Request = [System.UriBuilder]"$application/v1/company/time-offs?start_date=$STARTDATE&updated_from=$DIFFDATE"
#$Requestoffset = [System.UriBuilder]"$application/v1/company/time-offs?start_date=$STARTDATE"
# Setze TOKEN Header
$PERSONIO_TOKEN = Get-Token
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer $($PERSONIO_TOKEN.token)")
$GetVacationResult = Invoke-WebRequest -UseBasicParsing -Uri $Request.Uri -Method GET -Headers $headers -ContentType "application/json"
Return $GetVacationResult
}