 $log_folder= "C:\WEF\WefSourcesHealtCheck.log"
 function WefLog {
  param(
    [string]$computerName,
    [parameter(Mandatory=$false)]
    $subscriptionName = "Authentication"
)

$wecUtil={wecutil gr $args[0]}
$splatTable=@{}
if($computeRName) {$splatTable['ComputerName']=$computerName}
$in = Invoke-Command @splatTable $wecUtil -ArgumentList $subscriptionName
$in2 = ($in -join "`n")
$pattern = '(?<=\n)\t{2}(?!\t)(.+)\n\t{3}RunTimeStatus: (.+)\n\t{3}LastError: (.+)(?:\n\t{3}ErrorMessage: ((?:\n|.)+?)\n\t{3}ErrorTime: (.+)\n\t{3}NextRetryTime: (.+))?(?:\n|$)'
[regex]::Matches($in2,$pattern,'Multiline') | %{
    $arr = $_.Groups | select -skip 1 -exp value
     5 |select `
    @{Name='Name';Expression={$arr[0]}},
    @{Name='RunTimeStatus';Expression={$arr[1]}},
    @{Name='LastError';Expression={[int]$arr[2]}},
    @{Name='ErrorMessage';Expression={
        $msg = ([xml]$arr[3]).WSManFault.Message
        if($msg -is [string]) {$msg}
        else {$msg.ProviderFault.ProviderError.'#text'}
    }},
    @{Name='ErrorTime';Expression={[datetime]$arr[4]}},
    @{Name='NextRetryTime';Expression={[datetime]$arr[5]}}
    
    if($arr[1] -like 'Inactive'){
     
     $b= (Get-Date).ToString('yyyy-MM-dd hh:mm:ss')+" "+":"+":"+"1"+" "+"NoLogging"+" "+"-"+" "+"-"+" "+"443"+" "+"-"+" "+":"+":"+"1"+" "+$arr[0]+" "+"-"+" "+"302"+" "+"0"+" "+"0"+" "+"1996"+""+
     $b | Out-File $log_folder -Append  -Encoding UTF8
    }
}

}

if (!(Test-Path $log_folder))
{
   New-Item -ItemType Directory -Force -Path "C:\WEF"
   Out-File -FilePath "C:\WEF\WefSourcesHealtCheck.log" -Encoding UTF8
   $intro="#Logsign Wef Kaynakları İçin Source Healt Check Logları, support ; umit.gunes@logsign.net" | Out-File $log_folder -Append  -Encoding UTF8
                   WefLog 
   }
else
{
 
 WefLog

}