Share via

How to code this powershell script?

oemScript 81 Reputation points
2022-03-08T06:50:08.833+00:00

Referring to following coding, I would like to know on how to run code if today is Friday, Saturday or Sunday

if($datetime.DayOfWeek -match 'Sunday'){
coding
}

Does anyone have any suggestions?
Thanks in advance

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

Answer accepted by question author

Andreas Baumgarten 132.1K Reputation points MVP Volunteer Moderator
2022-03-08T07:13:08.637+00:00

Hi @oemScript ,

this might help:

$dayOfWeek = (Get-Date).DayOfWeek  
if ($dayOfWeek -eq "Friday" -or $dayOfWeek -eq "Saturday" -or $dayOfWeek -eq "Tuesday") {  
  Write-Output "It's $dayOfWeek ... lets start with some fancy stuff"  
} else {  
  Write-Output "It's $dayOfWeek ... lets wait and do nothing"  
}  

----------

(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. oemScript 81 Reputation points
    2022-03-08T14:00:41.203+00:00

    Thank you very much for suggestions (^v^)

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.