How do I migrate Azure DevOPs Iterations through the API and PS

I am trying to migrate iterations between two ADOs. I can retrieve the list of iterations just fine but I get an error when doing the Invoke-RestMethod POST. Here is the error I receive from the POST:

Invoke-RestMethod : {“$id”:”1″,”innerException”:null,”message”:”You
must provide a value for the iteration
parameter.”,”typeName”:”Microsoft.VisualStudio.Services.Common.VssPropertyValidationException,
Microsoft.VisualStudio.Services.Common”,”typeKey”:”VssPropertyValidationException”,”errorCode”:0,”eventId”:3000}
At C:UsersChrisDownloadsMigrateIterations.ps1:70 char:25

  • … $response = Invoke-RestMethod -Uri $TargetURL -Headers $Header -Metho …
  • Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    <code> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    </code>
    <code> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ </code>
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod],
      WebException
    • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

As I read the error I assume this is the salient part:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Invoke-RestMethod : {"$id":"1","innerException":null,"message":"You must provide a value for the iteration parameter.","typeName"
</code>
<code>Invoke-RestMethod : {"$id":"1","innerException":null,"message":"You must provide a value for the iteration parameter.","typeName" </code>
Invoke-RestMethod : {"$id":"1","innerException":null,"message":"You must provide a value for the iteration  parameter.","typeName"

But there is no iteration parameter “typeName”, or at least none I could find in any documentation. I even asked ChatGPT to write the script for me and it was essentially identical. The error must not be literal but I can’t find anything close online.

I tested my auth to the Target by retrieving a list of Iterations in the project and that worked fine, so my token is good.

Here is my script

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>$UserName = '[email protected]'
$SourceToken = <PAT>
$TargetToken = <PAT>
$SourceOrg = 'FirstADO'
$SourceProject = 'ProjectA'
$TargetOrg = 'SecondADO'
$TargetProject = 'ProjectB'
$URLBase = "https`://dev.azure.com/"
#log into source ADO
$sourceBase64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $UserName, $SourceToken)))
$Header = @{
Authorization = ("Basic {0}" -f $SourceBase64AuthInfo)
}
$SourceURL = "$URLBase/$SourceOrg/$SourceProject/_apis/work/teamsettings/iterations?api-version=6.0"
Write-Output $SourceURL
Try {
$SourceIterations = (Invoke-RestMethod $SourceURL -Headers $Header).value
}
Catch {
if ($_ -match "Access Denied") {
Throw "Access has been denied, please check your token"
}
else {
Throw $_
}
}
#log into target ADO
$TargetBase64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $UserName, $TargetToken)))
$Header = @{
Authorization = ("Basic {0}" -f $TargetBase64AuthInfo)
}
$TargetURL = "$URLBase/$TargetOrg/$TargetProject/_apis/work/teamsettings/iterations?api-version=6.0"
Write-Output $TargetURL
Try {
$TargetIterations = (Invoke-RestMethod $TargetURL -Headers $Header).value
}
Catch {
if ($_ -match "Access Denied") {
Throw "Access has been denied, please check your token"
}
else {
Throw $_
}
}
foreach ($item in $SourceIterations) {
Write-Output $item
$iterationPath = "{0}{1}" -f $TargetProject, $item.name
$jsonData = '{{
"name": "{0}",
"attributes": {{
"startDate": {1},
"finishDate": {2}
}}
}}' -f $item.name, $item.attributes.startDate, $item.attributes.finishDate
$JSON = $jsonData | ConvertTo-Json
try {
$response = Invoke-RestMethod -Uri $TargetURL -Headers $Header -Method Post -Body $JSON -ContentType application/json
Write-Output $response.value
}
catch {
Write-Output $_
}
}
</code>
<code>$UserName = '[email protected]' $SourceToken = <PAT> $TargetToken = <PAT> $SourceOrg = 'FirstADO' $SourceProject = 'ProjectA' $TargetOrg = 'SecondADO' $TargetProject = 'ProjectB' $URLBase = "https`://dev.azure.com/" #log into source ADO $sourceBase64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $UserName, $SourceToken))) $Header = @{ Authorization = ("Basic {0}" -f $SourceBase64AuthInfo) } $SourceURL = "$URLBase/$SourceOrg/$SourceProject/_apis/work/teamsettings/iterations?api-version=6.0" Write-Output $SourceURL Try { $SourceIterations = (Invoke-RestMethod $SourceURL -Headers $Header).value } Catch { if ($_ -match "Access Denied") { Throw "Access has been denied, please check your token" } else { Throw $_ } } #log into target ADO $TargetBase64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $UserName, $TargetToken))) $Header = @{ Authorization = ("Basic {0}" -f $TargetBase64AuthInfo) } $TargetURL = "$URLBase/$TargetOrg/$TargetProject/_apis/work/teamsettings/iterations?api-version=6.0" Write-Output $TargetURL Try { $TargetIterations = (Invoke-RestMethod $TargetURL -Headers $Header).value } Catch { if ($_ -match "Access Denied") { Throw "Access has been denied, please check your token" } else { Throw $_ } } foreach ($item in $SourceIterations) { Write-Output $item $iterationPath = "{0}{1}" -f $TargetProject, $item.name $jsonData = '{{ "name": "{0}", "attributes": {{ "startDate": {1}, "finishDate": {2} }} }}' -f $item.name, $item.attributes.startDate, $item.attributes.finishDate $JSON = $jsonData | ConvertTo-Json try { $response = Invoke-RestMethod -Uri $TargetURL -Headers $Header -Method Post -Body $JSON -ContentType application/json Write-Output $response.value } catch { Write-Output $_ } } </code>
$UserName = '[email protected]'
$SourceToken = <PAT>
$TargetToken = <PAT>
$SourceOrg = 'FirstADO'
$SourceProject = 'ProjectA'
$TargetOrg = 'SecondADO'
$TargetProject = 'ProjectB'

$URLBase = "https`://dev.azure.com/"

#log into source ADO
$sourceBase64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $UserName, $SourceToken)))
$Header = @{
    Authorization = ("Basic {0}" -f $SourceBase64AuthInfo)
}

$SourceURL = "$URLBase/$SourceOrg/$SourceProject/_apis/work/teamsettings/iterations?api-version=6.0"
Write-Output $SourceURL

Try {
    $SourceIterations = (Invoke-RestMethod $SourceURL -Headers $Header).value
}
Catch {
    if ($_ -match "Access Denied") {
        Throw "Access has been denied, please check your token"
    }
    else {
        Throw $_
    }
}

#log into target ADO
$TargetBase64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $UserName, $TargetToken)))
$Header = @{
    Authorization = ("Basic {0}" -f $TargetBase64AuthInfo)
}
$TargetURL = "$URLBase/$TargetOrg/$TargetProject/_apis/work/teamsettings/iterations?api-version=6.0"
Write-Output $TargetURL

Try {
    $TargetIterations = (Invoke-RestMethod $TargetURL -Headers $Header).value
}
Catch {
    if ($_ -match "Access Denied") {
        Throw "Access has been denied, please check your token"
    }
    else {
        Throw $_
    }
}

foreach ($item in $SourceIterations) {
    Write-Output $item

    $iterationPath = "{0}{1}" -f $TargetProject, $item.name
    $jsonData = '{{
      "name": "{0}",
      "attributes": {{
        "startDate": {1},
        "finishDate": {2} 
        }}
    }}' -f $item.name, $item.attributes.startDate, $item.attributes.finishDate

    $JSON = $jsonData | ConvertTo-Json

    try {
            $response = Invoke-RestMethod -Uri $TargetURL -Headers $Header -Method Post -Body $JSON -ContentType application/json
    Write-Output $response.value
    }
    catch {
        Write-Output $_
    }

}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật