Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Get current Year and Month
- $CurrYear = [datetime]::Now.Year
- $CurrMonth = [datetime]::Now.Month
- # Create new array with numbers from 1 to DaysInMonth
- 1..([datetime]::DaysInMonth($CurrYear, $CurrMonth)) |
- # For each element in array
- ForEach-Object {
- # Generate name for new directory in ddMMyyyy format
- # To do so, we create new DateTime Object with day from pipeline and current year and month
- # Then we convert it to the abovementioned format
- $DirName = ([datetime]::ParseExact("$_/$CurrMonth/$CurrYear", 'd/M/yyyy', [System.Globalization.CultureInfo]::InvariantCulture)).ToString('ddMMyyyy')
- # Correctly join path with current directory and new folder name
- $Path = Join-Path -Path (Get-Location).Path -ChildPath $DirName
- # Create new directory
- New-Item -ItemType Directory -Path $Path
- }
Advertisement
Add Comment
Please, Sign In to add comment