mardi 27 janvier 2015

PowerShell Get-Date into an Array

I'm trying to come up with some PowerShell code that is intended to be executed on Monday. If the script is executed on a different day, I'm looking for a way to use Get-Date to add/subtract days until DayOfWeek equals Monday.


The IF statement is working, thanks to http://ift.tt/1CwIPK2.


Now I'm stuck on two different aspects of this script.



  1. Logic to handle the script being run on any day besides Monday.

  2. As seen in the not working attempt in the Condition Matched block, I'm looking to get an array of Days from this code.


Code so far:



$d = [INT][DayOfWeek] "Monday"
IF ($d -ne 1)
{
'Condition matched'
for ($i = 0; $i -lt 7; $i++)
{$days = @((Get-Date).AddDays($i) | Select DayOfWeek)
$days[3]}

}
Else
{
'Condition not matched'
for ($i = 1; $i -le 7; $i++){$i}
}

Aucun commentaire:

Enregistrer un commentaire