$Organization = "https://dev.azure.com/org" # Make sure we are signed in to Azure $AccountInfo = az account show 2>&1 try { $AccountInfo = $AccountInfo | ConvertFrom-Json -ErrorAction Stop } catch { az login --allow-no-subscriptions } # Make sure we have Azure DevOps extension installed $DevOpsExtension = az extension list --query '[?name == ''azure-devops''].name' -o tsv if ($null -eq $DevOpsExtension) { $null = az extension add --name 'azure-devops' } # Destination project in DevOps $Project = "destination project" # Location of repositories $source = "C:\sourcepath" Get-ChildItem -path $source -Directory | ForEach-Object { # Create a repository with the same name as the folder az repos create --name $_.Name --project $Project --org "https://dev.azure.com/org" # Move to current folder set-location $_.FullName # Change the remote origin git remote set-url origin "https://org@dev.azure.com/org/project/_git/$($_.Name)" # Push the repo git push -u origin --all }