PowerShell命令在提示中使用时有输出,但在脚本中使用时没有输出(Update-TfsWorkspace)
问题描述:
我正在使用PSSnapin Teamfoundation.PowerShell,特别是使用cmdlet Update-TfsWorkspace。PowerShell命令在提示中使用时有输出,但在脚本中使用时没有输出(Update-TfsWorkspace)
我正在尝试脚本和自动化涉及从TFS获取最新内容的过程。当我使用命令:
Update-TfsWorkspace -force -item $somepath -recurse -overwrite
在PowerShell提示符下,我得到这样的输出:
Replacing 468256 C:\Path\MorePath\SomeFile1.txt
Replacing 468256 C:\Path\MorePath\SomeFile2.txt
Replacing 510850 C:\Path\MorePath\SomeFile3.txt
Replacing 468256 C:\Path\MorePath\SomeFile4.txt
Replacing 468256 C:\Path\MorePath\SomeFile5.txt
Replacing 510850 C:\Path\MorePath\SomeFile6.txt
Replacing 468256 C:\Path\MorePath\SomeFile7.txt
,这是我想要什么,并期望看到的。但是,当我在脚本中执行相同的命令而不是直接在提示符下输入空格而不是输出时。该命令执行成功,很明显,它的工作,但我没有得到输出。请参阅以下链接: Image of Empty Output
当使用启动脚本将日志记录到文件时,它会执行同样的操作。我得到输出,但输出只是空格。 See Here
我需要从这个命令的输出日志和顽固的拒绝脚本生成它似乎超出了我的专业知识。任何人有任何想法为什么会发生这种情况
答
注确定,因为我不使用它,它看起来像这样cmdlet时没有对产出写,但只在主机(请参见:Understanding Streams, Redirection, and Write-Host in PowerShell)
一个技巧就是把你的代码MyTFSScript.PS1
ANSD电话:
powershell.exe -noprofile -file MyTFSScript.PS1 > MyTFSScript.log