diff --git a/.gitignore b/.gitignore
index 1ba2a033c..97de89609 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,4 +2,5 @@
/sampleHelp.txt
/temp.txt
/pub.ps1
-test/sample.txt
\ No newline at end of file
+test/sample.txt
+/src/.vs
diff --git a/README.md b/README.md
index 1a6f02b8a..cbc731e8c 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,17 @@
# Team
-Future home of PowerShell module for accessing TFS and VSTS
+Home of PowerShell module for accessing TFS and VSTS
+To get started you can visit this blog [PowerShell I would like you to meet TFS and VSTS](http://www.donovanbrown.com/post/PowerShell-I-would-like-you-to-meet-TFS-and-VSTS)
+
+# Contributors
The cases of every file is very important. This module is to be used on Windows, Linux and OSx so case is important. If the casing does not match Linux and OSx might fail.
-To get started you can visit this blog [PowerShell I would like you to meet TFS and VSTS](http://www.donovanbrown.com/post/PowerShell-I-would-like-you-to-meet-TFS-and-VSTS)
+# Release Notes
+## 0.1.15
+Merge [Pull Request](https://github.com/DarqueWarrior/team/pull/3) from [Andy Neillans](https://github.com/aneillans) which included the following:
+- Corrected typos in help files.
+- Refactored location of common methods.
+- Implemented using DefaultCredentials when using TFS. This removes the need to create a PAT.
+
+## 0.1.14
+Initial Open Source release
\ No newline at end of file
diff --git a/Team.psd1 b/Team.psd1
index 8c91b8c86..1aa7b6c2d 100644
Binary files a/Team.psd1 and b/Team.psd1 differ
diff --git a/en-US/Team-Help.xml b/en-US/Team-Help.xml
index 8ddccb278..a2da28ba5 100644
--- a/en-US/Team-Help.xml
+++ b/en-US/Team-Help.xml
@@ -3179,28 +3179,32 @@ entire URL. Just the portion before visualstudio.com. For example in the
following url mydemos is the account name.
https://mydemos.visualstudio.com
or
-The ful Team Foundation Server (TFS) url including the collection.
+The full Team Foundation Server (TFS) url including the collection.
http://localhost:8080/tfs/DefaultCollection
String
-
+
PAT
A secured string to capture your personal access token. This will allow you
to provide your personal access token without displaying it in plain text.
-To use pat
+To use pat simply omit it from the Add-TeamAccount command.
SecureString
+
+
-
+
Level
-
+ On Windows allows you to store your account information at the Process, User or Machine levels. When saved at the User or Machine level your account information will be in any future PowerShell processes.
String
+
+
@@ -3220,19 +3224,49 @@ entire URL. Just the portion before visualstudio.com. For example in the
following url mydemos is the account name.
https://mydemos.visualstudio.com
or
-The ful Team Foundation Server (TFS) url including the collection.
+The full Team Foundation Server (TFS) url including the collection.
http://localhost:8080/tfs/DefaultCollection
String
-
+
Level
-
+ On Windows allows you to store your account information at the Process, User or Machine levels. When saved at the User or Machine level your account information will be in any future PowerShell processes.
+
+ String
+
+
+
+
+
+ Add-TeamAccount
+
+ Account
+
+
+ The Visual Studio Team Services (VSTS) account name to use. DO NOT enter the
+ entire URL. Just the portion before visualstudio.com. For example in the
+ following url mydemos is the account name.
+ https://mydemos.visualstudio.com
+ or
+ The full Team Foundation Server (TFS) url including the collection.
+ http://localhost:8080/tfs/DefaultCollection
+
String
+
+
+ UseWindowsAuthentication
+
+ Allows the use of the current user's Windows credentials to authenticate against a local TFS.
+
+ SwitchParameter
+
+
+
@@ -3245,7 +3279,7 @@ entire URL. Just the portion before visualstudio.com. For example in the
following url mydemos is the account name.
https://mydemos.visualstudio.com
or
-The ful Team Foundation Server (TFS) url including the collection.
+The full Team Foundation Server (TFS) url including the collection.
http://localhost:8080/tfs/DefaultCollection
String
@@ -3255,33 +3289,35 @@ http://localhost:8080/tfs/DefaultCollection
-
+
PAT
A secured string to capture your personal access token. This will allow you
to provide your personal access token without displaying it in plain text.
-To use pat
+To use pat simply omit it from the Add-TeamAccount command.
SecureString
SecureString
-
+
+
-
+
Level
-
+ On Windows allows you to store your account information at the Process, User or Machine levels. When saved at the User or Machine level your account information will be in any future PowerShell processes.
String
String
-
+
+
PersonalAccessToken
@@ -3295,6 +3331,16 @@ To use pat
+
+
+ UseWindowsAuthentication
+
+ Allows the use of the current user's Windows credentials to authenticate against a local TFS.
+
+ SwitchParameter
+
+
+
@@ -3318,6 +3364,16 @@ To use pat
Allows you to provide all the information on the command line.
+
+ -------------------------- EXAMPLE 3 --------------------------
+
+ PS C:\>
+
+ Add-TeamAccount -Account http://localtfs:8080/tfs/DefaultCollection -UseWindowsAuthentication
+
+ On Windows, allows you use to use Windows authentication against a local TFS server.
+
+
@@ -4333,8 +4389,7 @@ the Pipeline by Property Name
Name of the project to remove.
String
-
-
+
Force
@@ -4374,8 +4429,7 @@ the project.
String
-
-
+
@@ -4985,8 +5039,7 @@ you do not have to pass the ProjectName with each call.
Get all the repositories in your Visual Studio Team Services or Team Founcation Server account, or a specific project.
-
-
+
Get
GitRepository
@@ -5011,8 +5064,7 @@ You can use Set-DefaultProject to set a default project so
you do not have to pass the ProjectName with each call.
String
-
-
+
Id
@@ -5022,8 +5074,7 @@ commas to separate the IDs. To find the ID of a repository, type
Get-Repository.
Guid[]
-
-
+
@@ -5045,8 +5096,7 @@ you do not have to pass the ProjectName with each call.
String
-
-
+
Id
@@ -5060,8 +5110,7 @@ Get-Repository.
Int32[]
-
-
+
@@ -5139,8 +5188,7 @@ you do not have to pass the ProjectName with each call.
Specifies the name of the repository.
System.String
-
-
+
@@ -5174,8 +5222,7 @@ you do not have to pass the ProjectName with each call.
Int32[]
-
-
+
diff --git a/src/Approvals.psm1 b/src/Approvals.psm1
index 08c4927c3..ee4acb956 100644
--- a/src/Approvals.psm1
+++ b/src/Approvals.psm1
@@ -42,8 +42,12 @@ function Get-Approval {
try {
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
-
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
+
# Apply a Type Name so we can use custom format view and custom type extensions
foreach($item in $resp.value) {
_applyTypes -item $item
@@ -96,8 +100,12 @@ function Set-Approval {
try {
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Patch -Uri $listurl -ContentType "application/json" -Headers @{Authorization = "Basic $env:TEAM_PAT"} -Body $body
-
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Patch -Uri $listurl -ContentType "application/json" -Body $body -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Patch -Uri $listurl -ContentType "application/json" -Headers @{Authorization = "Basic $env:TEAM_PAT"} -Body $body
+ }
+
Write-Output "Approval $item status changed to $status"
}
catch {
diff --git a/src/buildDefinitions.psm1 b/src/buildDefinitions.psm1
index 5dfa366b9..5d28bec70 100644
--- a/src/buildDefinitions.psm1
+++ b/src/buildDefinitions.psm1
@@ -91,8 +91,12 @@ function Get-BuildDefinition {
}
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
-
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
+
_applyTypes -item $resp
Write-Output $resp
@@ -110,8 +114,12 @@ function Get-BuildDefinition {
}
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
-
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
+
# Apply a Type Name so we can use custom format view and custom type extensions
foreach($item in $resp.value) {
_applyTypes -item $item
@@ -141,7 +149,11 @@ function Add-BuildDefinition {
$url = _buildURL -projectName $projectName
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Post -Uri $url -ContentType "application/json" -Headers @{Authorization = "Basic $env:TEAM_PAT"} -InFile $inFile
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Post -Uri $url -ContentType "application/json" -UseDefaultCredentials -InFile $inFile
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Post -Uri $url -ContentType "application/json" -Headers @{Authorization = "Basic $env:TEAM_PAT"} -InFile $inFile
+ }
return $resp
}
@@ -170,7 +182,11 @@ function Remove-BuildDefinition {
if ($Force -or $pscmdlet.ShouldProcess($item, "Delete Build Definition")) {
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Delete -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Delete -Uri $listurl -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Delete -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
Write-Output "Deleted build defintion $item"
}
diff --git a/src/builds.psm1 b/src/builds.psm1
index 0457f440c..335bdeb72 100644
--- a/src/builds.psm1
+++ b/src/builds.psm1
@@ -107,7 +107,11 @@ function Get-Build {
$listurl = _buildURL -projectName $ProjectName -id $item
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
_applyTypes -item $resp
@@ -130,7 +134,11 @@ function Get-Build {
$listurl += _appendQueryString -name "definitions" -value ($definitions -join ',')
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
# Apply a Type Name so we can use custom format view and custom type extensions
foreach($item in $resp.value) {
@@ -199,7 +207,11 @@ function Add-Build {
Write-Verbose $body
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Post -ContentType "application/json" -Body $body -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Post -ContentType "application/json" -Body $body -Uri $listurl -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Post -ContentType "application/json" -Body $body -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
_applyTypes -item $resp
@@ -231,7 +243,11 @@ function Remove-Build {
if ($Force -or $pscmdlet.ShouldProcess($item, "Delete Build")) {
try {
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Delete -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Delete -Uri $listurl -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Delete -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
Write-Output "Deleted build $item"
}
diff --git a/src/cloudSubscriptions.psm1 b/src/cloudSubscriptions.psm1
index cbc640358..cd9b945fb 100644
--- a/src/cloudSubscriptions.psm1
+++ b/src/cloudSubscriptions.psm1
@@ -32,7 +32,11 @@ function Get-CloudSubscription {
$url = _buildURL
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $url -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $url -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $url -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
# Apply a Type Name so we can use custom format view and custom type extensions
foreach($item in $resp.value) {
diff --git a/src/common.ps1 b/src/common.ps1
index b09b4a503..f281ffe12 100644
--- a/src/common.ps1
+++ b/src/common.ps1
@@ -15,6 +15,10 @@ function _handleException {
Write-Warning (ConvertFrom-Json $ex.ToString()).message
}
+function _isOnWindows {
+ ($env:os -ne $null) -and ($env:os).StartsWith("Windows")
+}
+
# The url for release is special and used in more than one
# module so I moved it here.
function _buildReleaseURL {
@@ -64,7 +68,7 @@ function _getUserAgent {
$os = 'unknown'
- if ($PSVersionTable.PSVersion.Major -lt 6 -or $IsWindows) {
+ if ($PSVersionTable.PSVersion.Major -lt 6 -or (_isOnWindows)) {
$os = 'Windows'
} elseif ($IsOSX) {
$os = 'OSX'
@@ -75,6 +79,10 @@ function _getUserAgent {
return "Team Module/$($versionData.ModuleVersion) ($os) PowerShell/$($PSVersionTable.PSVersion.ToString())"
}
+function _useWindowsAuthenticationOnPremise {
+ return _isOnWindows -and (!$env:TEAM_PAT) -and -not ($env:TEAM_ACCT -like "*visualstudio.com")
+}
+
function _getProjects {
if(-not $env:TEAM_ACCT) {
Write-Output @()
@@ -91,7 +99,11 @@ function _getProjects {
# Call the REST API
try {
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
if ($resp.count -gt 0) {
Write-Output ($resp.value).name
diff --git a/src/git.psm1 b/src/git.psm1
index 35ff48d09..d276fa95f 100644
--- a/src/git.psm1
+++ b/src/git.psm1
@@ -55,7 +55,11 @@ function Remove-GitRepository {
if ($Force -or $pscmdlet.ShouldProcess($item, "Delete Repository")) {
try {
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Delete -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Delete -Uri $listurl -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Delete -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
Write-Output "Deleted repository $item"
}
@@ -98,7 +102,11 @@ function Add-GitRepository {
try {
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Post -ContentType "application/json" -Body $body -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Post -ContentType "application/json" -Body $body -Uri $listurl -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Post -ContentType "application/json" -Body $body -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
Write-Output $resp
}
@@ -138,7 +146,11 @@ function Get-GitRepository {
$listurl = _buildURL -projectName $ProjectName -id $item
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
_applyTypes -item $resp
@@ -149,7 +161,11 @@ function Get-GitRepository {
$listurl = _buildURL -projectName $ProjectName
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
# Apply a Type Name so we can use custom format view and custom type extensions
foreach($item in $resp.value) {
diff --git a/src/pools.psm1 b/src/pools.psm1
index a0bc87f64..c1530a057 100644
--- a/src/pools.psm1
+++ b/src/pools.psm1
@@ -60,7 +60,11 @@ function Get-Pool {
$url = _buildURL -id $id
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $url -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $url -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $url -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
_applyTypes -item $resp
@@ -69,7 +73,11 @@ function Get-Pool {
# Build the url
$url = _buildURL
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $url -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $url -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $url -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
# Apply a Type Name so we can use custom format view and custom type extensions
foreach($item in $resp.value) {
diff --git a/src/projects.psm1 b/src/projects.psm1
index 38b2ec69f..be8a4611a 100644
--- a/src/projects.psm1
+++ b/src/projects.psm1
@@ -45,7 +45,11 @@ function _checkStatus {
)
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $uri -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $uri -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $uri -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
return $resp
}
@@ -114,7 +118,11 @@ function Get-Project {
}
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
# Apply a Type Name so we can use custom format view and custom type extensions
_applyTypes -item $resp
@@ -126,7 +134,11 @@ function Get-Project {
try {
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
# Apply a Type Name so we can use custom format view and custom type extensions
foreach($item in $resp.value) {
@@ -191,7 +203,11 @@ function Update-Project {
Write-Verbose $body
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Patch -ContentType "application/json" -Body $body -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Patch -ContentType "application/json" -Body $body -Uri $listurl -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Patch -ContentType "application/json" -Body $body -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
_trackProgress -resp $resp -title 'Updating team project' -msg $msg
@@ -242,7 +258,11 @@ function Add-Project {
try {
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Post -ContentType "application/json" -Body $body -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Post -ContentType "application/json" -Body $body -Uri $listurl -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Post -ContentType "application/json" -Body $body -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
_trackProgress -resp $resp -title 'Creating team project' -msg "Name: $($Name), Template: $($processTemplate), Src: $($srcCtrl)"
@@ -277,7 +297,11 @@ function Remove-Project {
if ($Force -or $pscmdlet.ShouldProcess($ProjectName, "Delete Project")) {
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Delete -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Delete -Uri $listurl -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Delete -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
_trackProgress -resp $resp -title 'Deleting team project' -msg "Deleting $ProjectName"
diff --git a/src/queues.psm1 b/src/queues.psm1
index 5b8be9cfb..2416f0368 100644
--- a/src/queues.psm1
+++ b/src/queues.psm1
@@ -60,8 +60,11 @@ function Get-Queue {
if($id) {
# Build the url
$url = _buildURL -projectName $projectName -id $id
-
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $url -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $url -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $url -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
_applyTypes -item $resp
@@ -80,7 +83,11 @@ function Get-Queue {
}
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $url -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $url -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $url -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
# Apply a Type Name so we can use custom format view and custom type extensions
foreach($item in $resp.value) {
diff --git a/src/releaseDefinitions.psm1 b/src/releaseDefinitions.psm1
index db545d06a..10c25e9ef 100644
--- a/src/releaseDefinitions.psm1
+++ b/src/releaseDefinitions.psm1
@@ -59,7 +59,11 @@ function Get-ReleaseDefinition {
# Call the REST API
Write-Debug 'Get-ReleaseDefinition Call the REST API'
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
# Apply a Type Name so we can use custom format view and custom type extensions
_applyTypes -item $resp
@@ -74,7 +78,11 @@ function Get-ReleaseDefinition {
}
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
# Apply a Type Name so we can use custom format view and custom type extensions
foreach($item in $resp.value) {
@@ -108,7 +116,11 @@ function Add-ReleaseDefinition {
# Call the REST API
Write-Debug 'Add-ReleaseDefinition Call the REST API'
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Post -Uri $url -ContentType "application/json" -Headers @{Authorization = "Basic $env:TEAM_PAT"} -InFile $inFile
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Post -Uri $url -ContentType "application/json" -UseDefaultCredentials -InFile $inFile
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Post -Uri $url -ContentType "application/json" -Headers @{Authorization = "Basic $env:TEAM_PAT"} -InFile $inFile
+ }
Write-Output $resp
}
@@ -140,7 +152,11 @@ function Remove-ReleaseDefinition {
if ($force -or $pscmdlet.ShouldProcess($item, "Delete Release Definition")) {
# Call the REST API
Write-Debug 'Remove-ReleaseDefinition Call the REST API'
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Delete -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Delete -Uri $listurl -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Delete -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
Write-Output "Deleted release defintion $item"
}
diff --git a/src/releases.psm1 b/src/releases.psm1
index 7f8255763..cf5eed47d 100644
--- a/src/releases.psm1
+++ b/src/releases.psm1
@@ -76,7 +76,11 @@ function Get-Release {
# Call the REST API
Write-Debug 'Get-Release Call the REST API'
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
# Apply a Type Name so we can use custom format view and custom type extensions
_applyTypes -item $resp
@@ -97,7 +101,11 @@ function Get-Release {
$listurl += _appendQueryString -name "continuationToken" -value $continuationToken
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
# Apply a Type Name so we can use custom format view and custom type extensions
foreach($item in $resp.value) {
@@ -202,7 +210,11 @@ function Add-Release {
try {
Write-Debug 'Add-Release Call the REST API'
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Post -Uri $url -ContentType "application/json" -Headers @{Authorization = "Basic $env:TEAM_PAT"} -Body $body
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Post -Uri $url -ContentType "application/json" -UseDefaultCredentials -Body $body
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Post -Uri $url -ContentType "application/json" -Headers @{Authorization = "Basic $env:TEAM_PAT"} -Body $body
+ }
_applyTypes $resp
@@ -243,7 +255,11 @@ function Remove-Release {
try {
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Delete -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Delete -Uri $listurl -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Delete -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
Write-Output "Deleted release $item"
}
@@ -288,7 +304,11 @@ function Set-ReleaseStatus {
try {
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Patch -Uri $listurl -ContentType "application/json" -Headers @{Authorization = "Basic $env:TEAM_PAT"} -Body $body
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Patch -Uri $listurl -ContentType "application/json" -UseDefaultCredentials -Body $body
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Patch -Uri $listurl -ContentType "application/json" -Headers @{Authorization = "Basic $env:TEAM_PAT"} -Body $body
+ }
Write-Output "Release $item status changed to $status"
}
diff --git a/src/serviceendpoints.psm1 b/src/serviceendpoints.psm1
index 831739db9..e823da67e 100644
--- a/src/serviceendpoints.psm1
+++ b/src/serviceendpoints.psm1
@@ -61,7 +61,11 @@ function _checkStatus {
)
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $uri -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $uri -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $uri -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
return $resp
}
@@ -117,7 +121,11 @@ function Remove-ServiceEndpoint {
if ($Force -or $pscmdlet.ShouldProcess($item, "Delete Service Endpoint")) {
# Call the REST API
- Invoke-RestMethod -UserAgent (_getUserAgent) -Method Delete -Uri $url -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ Invoke-RestMethod -UserAgent (_getUserAgent) -Method Delete -Uri $url -UseDefaultCredentials
+ } else {
+ Invoke-RestMethod -UserAgent (_getUserAgent) -Method Delete -Uri $url -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
Write-Output "Deleted service endpoint $item"
}
@@ -174,7 +182,11 @@ function Add-AzureRMServiceEndpoint {
$body = $obj | ConvertTo-Json
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Post -Body $body -ContentType "application/json" -Uri $url -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Post -Body $body -ContentType "application/json" -Uri $url -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Post -Body $body -ContentType "application/json" -Uri $url -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
_trackProgress -projectName $projectName -resp $resp -title 'Creating Service Endpoint' -msg "Creating $endpointName"
@@ -201,7 +213,11 @@ function Get-ServiceEndpoint {
$url = _buildURL -projectName $projectName -id $id
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $url -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $url -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $url -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
_applyTypes -item $resp
@@ -211,7 +227,11 @@ function Get-ServiceEndpoint {
$url = _buildURL -projectName $projectName
# Call the REST API
- $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $url -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ if (_useWindowsAuthenticationOnPremise) {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $url -UseDefaultCredentials
+ } else {
+ $resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $url -Headers @{Authorization = "Basic $env:TEAM_PAT"}
+ }
# Apply a Type Name so we can use custom format view and custom type extensions
foreach($item in $resp.value) {
diff --git a/src/team.psm1 b/src/team.psm1
index 5265391c6..dd667ef0d 100644
--- a/src/team.psm1
+++ b/src/team.psm1
@@ -4,10 +4,6 @@ Set-StrictMode -Version Latest
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
. "$here\common.ps1"
-function _isOnWindows {
- ($env:os -ne $null) -and ($env:os).StartsWith("Windows")
-}
-
function _testAdministrator {
$user = [Security.Principal.WindowsIdentity]::GetCurrent()
(New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
@@ -50,6 +46,7 @@ function Get-TeamInfo {
function Add-TeamAccount {
[CmdletBinding(DefaultParameterSetName='Secure')]
param(
+ [parameter(ParameterSetName='Windows', Mandatory=$true, Position=1)]
[parameter(ParameterSetName='Secure', Mandatory=$true, Position=1)]
[Parameter(ParameterSetName='Plain')]
[string] $Account,
@@ -60,7 +57,7 @@ function Add-TeamAccount {
)
DynamicParam {
- # Only add this option on Windows Machines
+ # Only add these options on Windows Machines
if(_isOnWindows) {
Write-Verbose 'On a Windows machine'
@@ -92,9 +89,28 @@ function Add-TeamAccount {
# Add the ValidateSet to the attributes collection
$AttributeCollection.Add($ValidateSetAttribute)
+ $ParameterName2 = 'UseWindowsAuthentication'
+
+ # Create the dictionary
+ $RuntimeParameterDictionary2 = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
+
+ # Create the collection of attributes
+ $AttributeCollection2 = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
+
+ # Create and set the parameters' attributes
+ $ParameterAttribute2 = New-Object System.Management.Automation.ParameterAttribute
+ $ParameterAttribute2.Mandatory = $true
+ $ParameterAttribute2.ParameterSetName = "Windows"
+ $ParameterAttribute2.HelpMessage = "On Windows machines allows you to use the active user identity for authentication. Not available on other platforms."
+
+ # Add the attributes to the attributes collection
+ $AttributeCollection2.Add($ParameterAttribute2)
+
# Create and return the dynamic parameter
$RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection)
$RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
+ $RuntimeParameter2 = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName2, [switch], $AttributeCollection2)
+ $RuntimeParameterDictionary.Add($ParameterName2, $RuntimeParameter2)
return $RuntimeParameterDictionary
} else {
Write-Verbose 'Not on a Windows machine'
@@ -102,15 +118,6 @@ function Add-TeamAccount {
}
process {
- if ($PAT) {
- # Convert the securestring to a normal string
- # this was the one technique that worked on Mac, Linux and Windows
- $credential = New-Object System.Management.Automation.PSCredential $account,$PAT
- $_pat = $credential.GetNetworkCredential().Password
- } else {
- $_pat = $PersonalAccessToken
- }
-
if(_isOnWindows) {
# Bind the parameter to a friendly variable
$Level = $PSBoundParameters[$ParameterName]
@@ -118,16 +125,40 @@ function Add-TeamAccount {
if(-not $Level) {
$Level = "Process"
}
+
+ $UsingWindowsAuth = $PSBoundParameters[$ParameterName2]
+ if (!($PAT) -and !($PersonalAccessToken) -and !($UsingWindowsAuth)) {
+ Write-Error "Personal Access Token must be provided if you are not using Windows Authentication; please see the help."
+ }
+
} else {
$Level = "Process"
}
+
+
+ if ($PAT) {
+ # Convert the securestring to a normal string
+ # this was the one technique that worked on Mac, Linux and Windows
+ $credential = New-Object System.Management.Automation.PSCredential $account,$PAT
+ $_pat = $credential.GetNetworkCredential().Password
+ } else {
+ $_pat = $PersonalAccessToken
+ }
+
+
# If they only gave an account name add visualstudio.com
if($Account.ToLower().Contains('http') -eq $false) {
$Account = "https://$($Account).visualstudio.com"
}
- $encodedPat = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$_pat"))
+ $encodedPat = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$_pat"))
+
+ # If no PAT is entered, and on windows, are we using default credentials for REST calls
+ if ((!$_pat) -and (_isOnWindows) -and ($UsingWindowsAuth)) {
+ Write-Verbose "Using Default Windows Credentials for authentication; no Personal Access Token required"
+ $encodedPat = ""
+ }
_setEnvironmentVariables -Level $Level -Pat $encodedPat -Acct $account
}