Compare current time falls under given range of date-time,

%3CLINGO-SUB%20id%3D%22lingo-sub-2056944%22%20slang%3D%22en-US%22%3ECompare%20current%20time%20falls%20under%20given%20range%20of%20date-time%2C%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2056944%22%20slang%3D%22en-US%22%3E%3CP%3Emy%20task%20is%20to%3C%2FP%3E%3CP%3E1.check%20for%20Collection_Name%20as%20NOReboot%3CBR%20%2F%3E2.identify%20the%20timezone%3CBR%20%2F%3E3.check%20if%20timefalls%20under%20maintenance%20window%20timings%3CBR%20%2F%3E4.%20if%20falls%20under%20maintenance%20timings%20%2C%20check%20for%20Name_of_the_service%20column%3CBR%20%2F%3Eif%20service%20is%20abset%20%2C%20start%20reboot%3CBR%20%2F%3E%3CBR%20%2F%3Eif%20service%20is%20present%20%2C%20stop%20service%20--%26gt%3B%20reboot--%26gt%3B%20start%20service%3C%2FP%3E%3CP%3E----------------------------------------------------%3C%2FP%3E%3CP%3EMy%20code%20%3A%3C%2FP%3E%3CP%3E%24file%3D%22C%3A%5CUsers%5Csapantha%5CDownloads%5CAdtalem_collection.csv%22%3CBR%20%2F%3E%24data%3Dimport-csv%20%24file%3CBR%20%2F%3E%24results%3D%20%24data%20%7C%20WHERE%20%7B%24_.Collection_Name%20-eq%20%22NoReboot%22%7D%3CBR%20%2F%3E%24results%3CBR%20%2F%3E%24StartTime%20%3D%20%24results.Maintenane_Window_start_time%3CBR%20%2F%3E%24EndTime%20%3D%20%24results.Maintenane_Window_end_time%3CBR%20%2F%3E%24Current_time%20%3D%20Get-Date%20-Format%20%22dd-MM-yyyy%20HH%3Amm%3Ass%22%3C%2FP%3E%3CP%3Eforeach(%24item%20in%20%24results.Time_Zone%2C%24StartTime%20)%20%7B%3C%2FP%3E%3CP%3E%3CBR%20%2F%3Eif(%24Current_time%20-gt%20%24StartTime%20-and%20%24Current_time%20-lt%20%24EndTime)%7B%3CBR%20%2F%3E%24item%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWrite-Host%20%22will%20start%20reboot%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%7Delse%7B%3CBR%20%2F%3EWrite-Host%20%22waiting%20till%20time%20zone%20falls%20under%20maintenance%20%22%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3E---------------------------------%3C%2FP%3E%3CP%3E%26nbsp%3BI%20have%20attached%20the%20reference%20picture%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2056944%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWindows%20Server%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
New Contributor

my task is to

1.check for Collection_Name as NOReboot
2.identify the timezone
3.check if timefalls under maintenance window timings
4. if falls under maintenance timings , check for Name_of_the_service column
if service is abset , start reboot

if service is present , stop service --> reboot--> start service

----------------------------------------------------

My code :

$file="C:\Users\sapantha\Downloads\Adtalem_collection.csv"
$data=import-csv $file
$results= $data | WHERE {$_.Collection_Name -eq "NoReboot"}
$results
$StartTime = $results.Maintenane_Window_start_time
$EndTime = $results.Maintenane_Window_end_time
$Current_time = Get-Date -Format "dd-MM-yyyy HH:mm:ss"

foreach($item in $results.Time_Zone,$StartTime ) {


if($Current_time -gt $StartTime -and $Current_time -lt $EndTime){
$item

 

Write-Host "will start reboot"

 

}else{
Write-Host "waiting till time zone falls under maintenance "
}

 


}

---------------------------------

 I have attached the reference picture 

0 Replies