Quantcast
Channel: Team Foundation Server - General forum
Viewing all articles
Browse latest Browse all 6687

Typecast error in TFS API & PowerShell script

$
0
0

Hi all,

I have following powershell function and in this I am using Team Foundation Server API (TFS API) to copy area path  & iteration path from one team project to another team project of different collection.

                                              

Function BuildNodes(
            [Microsoft.TeamFoundation.Server.ProjectInfo] $sourceProj,
            [Microsoft.TeamFoundation.Server.ProjectInfo] $targetProj,
            [Microsoft.TeamFoundation.Server.ICommonStructureService4] $sourceCss,
            [Microsoft.TeamFoundation.Server.ICommonStructureService4] $targetCss,
            [string] $parentPath,
            [System.Xml.XmlNode] $parentNode,
            [System.Collections.Generic.List[Microsoft.TeamFoundation.Server.NodeInfo]] $sourceNodes,
            [string] $targetParentUri ){


        if( $parentNode.ChildNodes[0] -eq $null )
        {
            return
        }

        foreach( $childNode in $parentNode.ChildNodes[0].ChildNodes )
        {
            [string] $childNodePath = $childNode["Path"]

            $childNodeInfo = $sourceCss.GetNodeFromPath( $childNodePath )

            Write-Host "Source Area:" $childNodeInfo.Name
            Write-Host "Source Path:" $childNodeInfo.Path
            Write-Host "Source Area Uri:" $childNodeInfo.Uri
            Write-Host "Source Area Parent Uri:" $childNodeInfo.ParentUri
            Write-Host 

            $targetPath = $childNodeInfo.Path.Replace($sourceProj.Name, $targetProj.Name)

            # Create on the fly. The current Uri will be generated for the next call since we don't know the actual Uri of this node until it gets added
            $targetUri = $targetCss.CreateNode($childNodeInfo.Name, $targetParentUri)

            Write-Host "Target Area:" $childNodeInfo.Name
            Write-Host "Target Path:" $targetPath
            Write-Host "Target Area Uri:" $targetUri
            Write-Host "Target Area Parent Uri:" + $targetParentUri
            Write-Host 

            # call recursive
            BuildNodes $sourceProj, $targetProj, $sourceCss, $targetCss, $childNodePath, $childNode, $sourceNodes, $targetUri
        }
    }

When I run above powershell function, i am getting followoing error:-

Caught an exception:
Exception Type: System.Management.Automation.ParameterBindingArgumentTransformationException
Exception Message: Cannot process argument transformation on parameter 'sourceProj'. Cannot convert the "System.Object[]" value of type "System.Object[]" to type "Microsoft.TeamFo
undation.Server.ProjectInfo".

I am clueless how can I fix this issue.Please help me. Thanks.


Viewing all articles
Browse latest Browse all 6687

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>