DEV Community

Roberth Strand
Roberth Strand

Posted on • Originally published at robstr.dev on

Adding a year worth of sprints in Azure DevOps with PowerShell

Alt Text

If you are working with Azure DevOps to keep track of your projects, you probably have to deal with sprints. Depending on the length of your sprints, and the fact that you can bulk add sprints, you probably either end up creating the next sprint during sprint planning or create every sprint manually.

Obviously, we hate manual tasks, so this is something we need to fix. Especially since our team is using one week sprints, and I don't want to do anything 52 times. When you read through the following script, make sure to adjust accordingly to fit your sprint length.

First, we need the VSTeam module. You can install it from PowerShellGallery by running the following:

Install-Module -Name VSTeam
Enter fullscreen mode Exit fullscreen mode

Next you would need to add your personal access token to your session, so you can actually add the sprints. You can create a personal access token by clicking the avatar with the cogwheel on in the right corner of Azure DevOps, and chose the menu option personal access tokens.

Set-VSTeamAccount -Account 'Organization Name' -PersonalAccessToken 'Token'
Enter fullscreen mode Exit fullscreen mode

Then, we do all the magic stuff. We create a loop, which starts on the first Monday of the year and continues throughout the entire year.

# Add the first date that we want the loop to start at.
# For the year of 2021, the first week would start on
# Monday the 4th
$date = Get-Date -Year 2021 -Month 1 -Day 4

while ($date.Year -ne "2022") {
    # Set date for the end of the sprint,
    # in this case a five day work week.
    $EndDate = $date.AddDays(4)
    if ($EndDate.Year -eq "2022") {
        # For the last sprint, so that it ends on the last day
        # of the year, not into next year.
        $EndDate = Get-Date -Year 2021 -Month 12 -Day 31
    }
    # Using Unix format, we can easily get the week number:
    $week = Get-Date $date -UFormat "%V"

    # Putting it all together, and adding the next sprint.
    # Notice that the name is using the week variable
    # in the format that our team uses.
    $Sprint = @{
        Name = "2021-W$week"
        ProjectName = 'ProjectName'
        StartDate = $date
        FinishDate = $EndDate
    }
    Add-VSTeamIteration @Sprint

    # bump the date we are working on with a week
    $date = $date.AddDays(7)
}
Enter fullscreen mode Exit fullscreen mode

Like I mentioned, this creates the 52 weekly sprints for the year 2021. If you need to, you could set the end date to add 9 days instead of 4 so that you get two weeks, and then you would need to bump the date at the end by 14.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay