Link to home
Start Free TrialLog in
Avatar of cornetthd
cornetthd

asked on

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
Avatar of Wonko_the_Sane
Wonko_the_Sane
Flag of United States of America image

Something like that should work:

$d = get-date
if ($d.dayofweek -eq 'Monday') {
          code to execute goes in here
ASKER CERTIFIED SOLUTION
Avatar of Wonko_the_Sane
Wonko_the_Sane
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cornetthd
cornetthd

ASKER

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
}