我需要创建名为的文件夹:
Week1-Sat
Week1-Sun
Week2-Sat
...
WeekX-Sat
WeekX-Sun
手动创建它们会花费太长时间。
我需要能够快速创建空目录并允许从父文件夹继承权限。
(这些文件夹经常被创建和删除)
答案1
你只需要两个嵌套循环:
## 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
}
}
对于继承/传播,请参阅此stackoverflow.com 上的问答