PS 新项目:访问被拒绝从命令行正常运行,但在从 TFS 构建执行期间不能正常运行 [英] PS New-Item : Access is denied runs fine from command line but not during execution from TFS build

查看:25
本文介绍了PS 新项目:访问被拒绝从命令行正常运行,但在从 TFS 构建执行期间不能正常运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个由 TFS 构建触发的脚本,该脚本在网络共享上创建一个新目录,然后将该共享的位置保存在环境变量中.

I'm trying to create a script that's triggered by a TFS build that creates a new directory on a network share and then saves the location of that share in an environment variable.

这是原来的(删节)脚本:

Here's the (abridged) script as it originally was:

$NewPathForFiles = "\\NetworkShareName \" + "ProductName "+ $MajorBuildNumber 

New-Item -Path $NewPathForFiles -ItemType directory # Create the folder

但是当我从 TFS 运行脚本时,出现此错误:

But when I run the the script from TFS I get this error:

New-Item : Access is denied

即使以运行 TFS 构建的服务帐户身份登录,我也可以从命令提示符运行脚本,但在构建中我收到错误消息.

I can run the script from the command prompt even logged in as the service account running TFS build, but from within the build I get the error.

我通过使用 -Credential 将驱动器映射到共享来解决此问题,但这意味着我需要在脚本中对 ID 的密码进行硬编码,而我不想这样做:

I fixed this by mapping a drive to the share using -Credential, but that means I need to hard-code the password for the ID in the script which I'd prefer not to do:

$pass = ConvertTo-SecureString "MyPassword" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential("MyID",$pass)

New-PSDrive -Name P -PSProvider FileSystem -Root "\\MyNetworkShare" -Credential $cred

$NewPathForFiles = "p:\ProdctName " + $MajorBuildNumber 

New-Item -Path $NewPathForFiles -ItemType directory # Create the folder

有人知道如何在无需对 PW 进行硬编码的情况下做到这一点吗?

Anyone have any ideas how I can do this without having to hard-code the PW?

推荐答案

感谢 @TheIncorrigible1 的回答.将 -Force 添加到 New-Item 解决了该问题.谢谢!

Thanks to @TheIncorrigible1 for the answer. Adding the -Force to the New-Item fixed the issue. Thanks!

这篇关于PS 新项目:访问被拒绝从命令行正常运行,但在从 TFS 构建执行期间不能正常运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆