• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 498
  • Last Modified:

Execute a portion of a Powershell Script on a Specific Day

Is there a way to setup a portion of a powershell script to execute on a specific day.

Ex.
If Day = Monday
execute code
Else Skip
0
cornetthd
Asked:
cornetthd
  • 2
1 Solution
 
Wonko_the_SaneCommented:
Something like that should work:

$d = get-date
if ($d.dayofweek -eq 'Monday') {
          code to execute goes in here
0
 
Wonko_the_SaneCommented:
Wrong button... Again:

Something like that should work:

$d = get-date
if ($d.dayofweek -eq 'Monday') {
          code to execute goes in here
          }

0
 
cornetthdAuthor Commented:
This worked perfectly.  I modified it a little to add a variable for the day.

$d = get-date
$day = 'Monday'
if ($d.dayofweek -eq $day) {
Code to Execute
}

I used this portion of the script in mutilple places.

if ($d.dayofweek -eq $day) {
Code to Execute
}
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now