MethodsAndPractices / vsteam

PowerShell module for accessing Azure DevOps Services and Azure DevOps Server (formerly VSTS or TFS)

Home Page:https://methodsandpractices.github.io/vsteam-docs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Import-Module fails with error message when default Project not with common scopes set

mpiederiet opened this issue · comments

Steps to reproduce

  • Start a new PowerShell window (tested with PowerShell Core 7.2.3 but also Windows PowerShell 5)
  • Import the VSTeam module
  • Connect using Set-VSTeamAccount without using the -Level param (so it defaults to level 'Process')
Set-VSTeamDefaultProject -Project '<Name of an existing project>' -Scope 'User'

or (when this PowerShell window is running as Administrator)

Set-VSTeamDefaultProject -Project '<Name of an existing project>' -Scope 'Machine'
  • Start a new PowerShell window
  • Import the VSTeam module

Expected behavior

I expected that I could import the module without issues

Actual behavior?

The Import-Module failed with error message You must call Set-VSTeamAccount before calling any other functions in this module

On Which OS have you tried it?

Windows

What was your server version?

Azure DevOps Services

Other server version

No response

Log output of used API

Billing                     : 5.1-preview.1
Build                       : 5.1
Core                        : 5.1
DistributedTask             : 6.0-preview
DistributedTaskReleased     : 5.1
ExtensionsManagement        : 6.0-preview
Git                         : 5.1
Graph                       : 6.0-preview
HierarchyQuery              : 5.1-preview
MemberEntitlementManagement : 6.0-preview
Packaging                   : 6.0-preview
Pipelines                   : 5.1-preview
Policy                      : 5.1
Processes                   : 6.0-preview
Release                     : 5.1
ServiceEndpoints            : 5.0-preview
TaskGroups                  : 6.0-preview
Tfvc                        : 5.1
VariableGroups              : 5.1-preview.1
Version                     :
Wiki                        : 6.0
WorkItemTracking            : 6.0-preview.1

Log output of $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.2.3
PSEdition                      Core
GitCommitId                    7.2.3
OS                             Microsoft Windows 10.0.19044
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0, 5.0, 5.1.10032.0, 6.0.0, 6.1.0, 6.2.0, 7.0.0, 7.1.0, 7.2.3}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

I already found out that the Import-Module fails because of this line in VSTeam.psm1:

if (Get-VSTeamProject | Where-Object ProjectName -eq $env:TEAM_PROJECT) {

The Get-VSTeamProject command can't be executed here because there are no stored credentials. I think it would be a good idea to check for credentials before executing Get-VSTeamProject
Maybe even better:
check for stored credentials, then check for stored default Project name, then check whether that project still exists and throw a warning if it doesn't.

Working on it now