0

I need to create folders called:

Week1-Sat
Week1-Sun
Week2-Sat
...
WeekX-Sat
WeekX-Sun

creating them manually would take too long.

I need to be able to quickly create empty directories and allow the permissions to be inherited from the parent folder.
(These folders get created and deleted often)

  • What have you tried, where are you having problems with? – LotPings Feb 8 at 12:56
2

You just need two nested loops:

## Q:\Test\2019\02\08\SF_952895.ps1
$AbbreviatedDayNames = [System.Globalization.DateTimeFormatInfo]::CurrentInfo.AbbreviatedDayNames

for ($Week=1;$Week -lt 53;$Week++){
    0..6|ForEach-Object{
        $Folder = "Week{0}-{1}" -f $Week,$AbbreviatedDayNames[$_]
        New-Item $Folder -ItemType Directory
    }
}

For inheritance/propagation see this Q&A on stackoverflow.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.