majkinetor / TFS

Powershell module to drive TFS 2015+ via REST interface

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue with executing TFS powershell module

mishra1010 opened this issue · comments

Hi Miodrag,

I am facing issues while implementing this module to connect to TFS 2015 RTM.

  1. Install-Module TFS and now it lists all the functions available.
  2. Created env variable in tfsenv.ps1:
$tfs=@{
root_url='http://tfs-2015:8080/tfs'
collection='ReproIssues'
project='buildrepo'
credential=Get-Credential
api_version='1.0'
}
  1. Downloaded get-credential module but do not know how to set the credentials here. i just gave $tfs.credential=Get-Credential in the powershell window.
  2. Then when i execute gcm -m tfs, it shows the list.
  3. But then i execute a script, nothing really happens :(
PS C:\share\TFS-master\TFS-master>> .\Get-TFSProjects.ps1 -Verbose
PS C:\share\TFS-master\TFS-master>>

Please help.

Hello @mishra1010

I formatted a bit your input. Please make sure you format it correctly in advance.

You are not using the module correctly. You also didn't configure it correctly.

  • Created env variable in tfsenv.ps1
    Your variable must be visible in the active shell where you execute commands. You must type $tfs in it and see TFS details. If you didn't call above script as . ./tfsenv.ps1 (notice the dot) then it wont do. Put $tfs var in your $PROFILE.
  • But then i execute a script, nothing really happen
    You do not call the script. You call module command: Get-TFSProjects -Verbose or better try defs -Verbose (alias for Get-TFSBuildDefinitions) as that is probably what you want, Get-TFSProjects is totally irrelevant for majority of users.

Suggestion: You should learn Powershell basics on modules.

BTW, use this TFS setting:

$global:tfs=@{
    root_url='http://tfs-2015:8080/tfs'
    collection='ReproIssues'
    project='buildrepo'
}

Sure, Point noted. While i learn more about PS, i get the following error now:

PS C:\share\TFS-master\TFS-master> $tfs

Name                           Value
----                           -----
collection                     ReproIssues
project                        buildrepo
api_version                    1.0
root_url                       http://tfs-2015:8080/tfs
credential                     System.Management.Automation.PSCredential

PS C:\share\TFS-master\TFS-master> defs -Verbose
VERBOSE: TFS Credential: fareast\demishra
VERBOSE: URI: /DefaultCollection//_apis/build/definitions?api-version=1.0
Invoke-RestMethod : Invalid URI: The hostname could not be parsed.
At C:\Program Files\WindowsPowerShell\Modules\tfs\2016.5.18\_globals.ps1:21 char:9
+         Invoke-RestMethod @Params
+         ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Invoke-RestMethod], UriFormatException
    + FullyQualifiedErrorId : System.UriFormatException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Your $tfs variable is not considered which means its not set right. You can see that it still points to DefaultCollection and that URI (which comes from root_url) is missing.

BTW, please remove api_version from the $tfs definition and try again. V1 is outdated.

Put above mentioned config in your $PROFILE, start the new shell and try any command.

This works now and i get the build definitions but i would like to get the list of team projects which does not work. Any ideas how i can make it to work?

Anyways thanks a lot for helping. Now i understand how the module works.

Get-TFSProjects -Verbose

Get-TFSProjects does not work actually as i mentioned in my first post today and still its the same. Please find the output.
PS C:\share\TFS-master\TFS-master> .\Get-TFSProjects.ps1
PS C:\share\TFS-master\TFS-master> .\Get-TFSProjects.ps1 -Verbose
PS C:\share\TFS-master\TFS-master>

Dude, please, learn to use Posh. You are again reverting to your old behavior. I posted you command above.

Got It, Thanks a lot. I just thought of it as a PS script and was using it the same way. Need to get some knowledge on Posh, Thanks a ton!!!!