简体   繁体   English

如何解决Add-PSSnapin Microsoft.TeamFoundation.PowerShell和Get-TfsChildItem错误?

[英]How to resolve the Add-PSSnapin Microsoft.TeamFoundation.PowerShell and Get-TfsChildItem error?

Below is the PowerShell Script that I am using to download the folder from TFS 2013 Update 4 to my local machine but i am getting some exception which I have copied below the code. 下面是我用来将文件夹从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)))
    }
}

Exception that occurs is: 发生的异常是:

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

Please make sure you have fully installed the TFS Powertools . 请确保您已完全安装TFS Powertools

By default it doesn't install the PowerShell CmdLets . 默认情况下,它不会安装PowerShell CmdLets If it is, just install it and then the issue will be gone. 如果是,只需安装它然后问题就会消失。

Another possibility is that the PowerShell Snap-in is stored in the inconsistent registry with the OS version (32bit/64bit). 另一种可能性是PowerShell管理单元存储在与OS版本(32位/ 64位)不一致的注册表中。

PowerTools installer is 32bit, on 64bit machine, it will write to HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\PowerShell\\1\\PowerShellSnapIns , but not to HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\PowerShell\\1\\PowerShellSnapIns. PowerTools安装程序是32位,在64位机器上,它将写入HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\PowerShell\\1\\PowerShellSnapIns ,但不会写入HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\PowerShell\\1\\PowerShellSnapIns.

Reference this similar thread for details: TFS Power Tools 2008 Powershell Snapin won't run in on 64-bit in Windows 2008 R2? 有关详细信息,请参阅此类似线程: TFS Power Tools 2008 Powershell Snapin将无法在Windows 2008 R2中的64位上运行?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法为Microsoft.TeamFoundation.PowerShell添加PSSnapin,获取与无法投射对象有关的错误 - Unable to add PSSnapin for Microsoft.TeamFoundation.PowerShell getting error related to unable to cast object Powershell错误Add-PSSnapin“ Microsoft.SharePoint.PowerShell” - Powershell error Add-PSSnapin “Microsoft.SharePoint.PowerShell” Powershell Get-TfsWorkspace 未找到作为另一个用户创建的工作区。 (Microsoft.TeamFoundation.PowerShell) - Powershell Get-TfsWorkspace not finding workspace created as another user. (Microsoft.TeamFoundation.PowerShell) 无法将pssnapin microsoft.exchange.management.powershell.admin添加到Powershell Studio脚本 - Unable to add-pssnapin microsoft.exchange.management.powershell.admin to powershell studio script Add-PSSnapin'Microsoft.SharePoint.PowerShell'在ISE中运行,但不是从.Net Process.Start命令运行 - Add-PSSnapin 'Microsoft.SharePoint.PowerShell' runs in ISE but not from .Net Process.Start command TFS Build:此计算机上未安装`Microsoft.TeamFoundation.PowerShell' - TFS Build: `Microsoft.TeamFoundation.PowerShell' is not installed on this computer 如何在调用Add-PSSnapin之前检查是否已加载PowerShell管理单元 - How to check if PowerShell snap-in is already loaded before calling Add-PSSnapin 将-ea与Add-PSSnapin一起使用时Powershell停止工作 - Powershell stops working when using -ea with Add-PSSnapin Powershell Add-PSSnapin VMWare.VimAutomation.Core问题 - Powershell Add-PSSnapin VMWare.VimAutomation.Core issues 来自高级(cmdlet)函数的PowerShell Add-PSSnapIn - PowerShell Add-PSSnapIn from an advanced (cmdlet) function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM