I am writing a Powershell script as part of a Visual Studio Team Services build, this build uses a hosted build controller. The script is intended to check out a file, make changes then check it back in.
In the script I am trying to invoke the tf
command to create a new workspace but I'm having authentication issues. The command
& $tf vc workspace /new $tempWorkspaceName /collection:https://mycollection.visualstudio.com/
produces the error:
TF30063: You are not authorized to access https://mycollection.visualstudio.com/.
How can I access TFS from my Powershell script without embedding logins or passwords in the script? Can I access TFS within the context of the build agent, which itself logs in to TFS? Or is there another way I should be doing this?
Note that I haven't used the TFS Power Tool cmdlets as it is a hosted build server. Using the TFS RestAPI also doesn't appear to be an option as there is no facility to check a file in or out.
PowerShell Extension Once you install the extension, you can create a new PowerShell script by pressing Ctrl+N and then saving it as a PS1 file using Ctrl+S . Once it is saved as a PS1, VS Code will identify the file as a PowerShell script. From there, you can execute the PowerShell script by press F5 .
Visual Studio Code with the PowerShell extension is the recommended editor for writing PowerShell scripts. It supports the following PowerShell versions: PowerShell 7.0 and higher (Windows, macOS, and Linux)
About TF Command, you can check this article.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With