- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
下面是我用来将文件夹从 TFS 2013 Update 4 下载到我的本地计算机的 PowerShell 脚本,但我遇到了一些异常,我已将其复制到代码下方。
$AutoDeployDir = "$/Intel/Installscript/Utility Scripts"
$deployDirectory = "C:\powershell scripts\New folder\Demo TFS Code"
# Add TFS 2013 dlls so we can download some files
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.VersionControl.Client")
$tfsCollectionUrl = "http://stptfs2013dbsvr:8080/tfs/intelcollection"
$tfsCollection = New-Object -TypeName Microsoft.TeamFoundation.Client.TfsTeamProjectCollection -ArgumentList $tfsCollectionUrl
$tfsVersionControl = $tfsCollection.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer])
# Register PowerShell commands
Add-PSSnapin Microsoft.TeamFoundation.PowerShell
# Get all directories and files in the AutoDeploy directory
$items = Get-TfsChildItem $AutoDeployDir -Recurse -Server $tfsCollection
# Download each item to a specific destination
foreach ($item in $items) {
# Serverpath of the item
Write-Host "TFS item to download:" $($item.ServerItem) -ForegroundColor Blue
$destinationPath = $item.ServerItem.Replace($AutoDeployDir, $deployDirectory)
Write-Host "Download to" $([IO.Path]::GetFullPath($destinationPath)) -ForegroundColor Blue
if ($item.ItemType -eq "Folder") {
New-Item $([IO.Path]::GetFullPath($destinationPath)) -ItemType Directory -Force
}
else {
# Download the file (not folder) to destination directory
$tfsVersionControl.DownloadFile($item.ServerItem, $([IO.Path]::GetFullPath($destinationPath)))
}
}
发生的异常是:
Add-PSSnapin : The Windows PowerShell snap-in 'Microsoft.TeamFoundation.PowerShell' is not installed on this computer.
At C:\powershell scripts\demo1.ps1:12 char:1
+ Add-PSSnapin Microsoft.TeamFoundation.PowerShell
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Microsoft.TeamFoundation.PowerShell:String) [Add-PSSnapin], PSArgumentException
+ FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand
Get-TfsChildItem : The term 'Get-TfsChildItem' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\powershell scripts\demo1.ps1:15 char:10
+ $items = Get-TfsChildItem $AutoDeployDir -Recurse -Server $tfsCollection
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-TfsChildItem:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
最佳答案
请确保您已完全安装 TFS Powertools .
默认情况下,它不会安装 PowerShell CmdLets。如果是,只需安装它,然后问题就会消失。
另一种可能是 PowerShell Snap-in 存储在与操作系统版本(32 位/64 位)不一致的注册表中。
PowerTools installer is 32bit, on 64bit machine, it will write to
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\PowerShell\1\PowerShellSnapIns
, but not toHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellSnapIns.
有关详细信息,请引用此类似主题:TFS Power Tools 2008 Powershell Snapin won’t run in on 64-bit in Windows 2008 R2?
关于powershell - 如何解决 Add-PSSnapin Microsoft.TeamFoundation.PowerShell 和 Get-TfsChildItem 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47647637/
下面是我用来将文件夹从 TFS 2013 Update 4 下载到我的本地计算机的 PowerShell 脚本,但我遇到了一些异常,我已将其复制到代码下方。 $AutoDeployDir = "$/I
我是一名优秀的程序员,十分优秀!