Powershell Skript to check EOL Dates in CSV File

Hi all :raised_hand_with_fingers_splayed:,

i´m really new into Powershell Scripting and i hope i can get some help from you.

Situation: I created an Script which checking the Windows Version of the Server and compare it with a List of support Versions in a CSV File. Really Simple.

$winver = (get-wmiobject Win32_OperatingSystem).caption

$EOLList = @()
Import-Csv -Path C:\__LocalData\EOL.csv | ForEach-Object {$EOLList += $_.WindowsVersion}

If ($EOLList -contains $winver) {
    write-host "Windows OK"
}

else{
    write-host "EOL"
}

Now i want to extend the Script and the CSV File. I added the EOL Dates to the CSV File.

WindowsVersion                                      Date      
--------------                                      ----      
Microsoft Windows Server 2019                       09.01.2029
Microsoft Windows Server 2016                       11.01.2027
Microsoft Windows Server 2012R2                     10.10.2023
Microsoft Windows Server 2012                       10.10.2023

I want to check if the current Server Version is in this List and also check how many Days left to the EOL Date.

I hope some of you guys can help me with this :grinning:

ptsonic,
Welcome to the forum. :wave:t4:

I’m not completely sure if I got what you want to do actually. If I got it right I’d do it a little different. I’d use a hashtable as lookup table (and I added an entry for Windows 10 with a fictional date because I didn’t have a server to test :wink: )

$LookUpTable = @{
    'Microsoft Windows Server 2019'   = '09.01.2029'
    'Microsoft Windows Server 2016'   = '11.01.2027'
    'Microsoft Windows Server 2012R2' = '10.10.2023'
    'Microsoft Windows Server 2012'   = '10.10.2023'
    'Microsoft Windows 10 Pro'        = '31.12.2044'
}
$CurrentSystem = Get-CimInstance -ClassName CIM_OperatingSystem | Select-Object -ExpandProperty Caption
$DaysCount = New-TimeSpan -Start (Get-Date) -End $LookUpTable[$CurrentSystem]

"`n`tThe support for the current system will end in {0} days form now, at {1}.`n" -f ($DaysCount.TotalDays -as [int]) , $LookUpTable[$CurrentSystem]

Could you please format your code as code next time? As you can see it is incomplete because the forum software tried to interpret it and removed some charachters in this process. This will not happen when you use the preformatted text button ( </> ) to post your code.

Thanks in advance.

Hi Olaf,

thanks for your fast answer. Firstable i correct my post and formated the code :wink:

I will try your solution tomorrow.

The Final Situation is that i want to implement a Sensor in Icinga that will show me the Status of the Operation System.

OK (Green) – Windows under support
Warning (Orange) – Support will end in X Days
Error (Red) – Product is End of life

Hi Olaf,

i just want let you know the Solution works fine :grinning:
Thanks for your fast answer.