Share via


In Power-shell Error tf : TF30063: You are not authorized to access

Question

Monday, October 16, 2017 7:15 AM

Hi All,

Am using one of build agent machine using power-shell to access the TFS, to create a new work-space and mapping local folder.

Power-shell Version --> V3.0

Visual Studio --> 2015

Power Tool installed based on visual studio version.

The below script for used:

param(

$Projectcollection = 'https://test15/tfs/newcollection',
$droppath = $Env:Build_StagingDirectory,
$Sharedbinaryname = '*..dll,*.dll,*.dll',
$Username = 'Username',
$Password = 'pwd',
$Checkinpath = '$/test/samplecode/SharedBinaries'
)

try{

    write-verbose "The Shared binary check-in process started" -Verbose

    # Create a local working directory
    $temp = (Get-Date -f MMddyyyyhhmm)
    $Localworkingfolder = "$env:homedrive\SharedBinary"
    if (!(Test-Path $Localworkingfolder -PathType Container)) 
    {
        New-Item -ItemType Directory -Force -Path $Localworkingfolder 
    }
    else
    {
        remove-item "$Localworkingfolder\" -Force -Recurse
    }

    # Get the TeamFoundation PowerShell cmdlets
    Add-PSSnapin Microsoft.TeamFoundation.Powershell

    # Set the TF.exe path
    $tfexe = 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\TF.exe'

    # Move to current working path
    cd $Localworkingfolder

    # Set a new workspace
    & $tfexe workspace /new Tmp_workspace /collection:$Projectcollection  /login:$Username,$Password

    # Map the workfolder for Shared binary
    & $tfexe workfold /map "$Checkinpath" "$Localworkingfolder" /collection:$Projectcollection /workspace:Tmp_workspace /login:$Username,$Password

}

Catch {
Write-Error "Checks your inputs"

}

Error : tf : TF30063: You are not authorized to access 'https://test15/tfs/newcollection'

But the user-name, Password are correct.

The Same script was executed in window command its working fine. But executed in Powers-shell is through an error.

What is the issue ?

Thanks in advance!

Thanks

Sudalai.

All replies (3)

Monday, October 16, 2017 10:09 AM

If you are not authorized then there is nothing that PowerShell can do about it.  Get a TFS admin to authorize you to use the API and to access the resources you need to change. It also appears you are not using the CmdLets.

See this to learn how to use the CmdLets: https://github.com/igoravl/tfscmdlets (scroll down),

\(ツ)_/


Monday, October 16, 2017 12:02 PM

Hi 

okay

But the same script was executed in my local machine it successfully working fine. But i tried in build agent machine it was failed.

For Example: Simple example

tf workspace /new Tmp_workspace /collection:https://test15/tfs/newcollection /login:Username,pwd

The above line working successfully to create a new workspace through windows command. But failed to execute in window power-shell.

Thanks

Sudalai.


Monday, October 16, 2017 12:19 PM | 1 vote

Open PS and type "tf" and see what happens.

If TF is found on the path then use Start-Process to run the command.  The username and password must be enclosed in quotes:

/login:"$Username,$Password"

It is a comma separated string.  In PowerShell you are sending it as an array of two strings.

\(ツ)_/