开发者

Add-member in iteration doesn't work in PowerShell

Here is the code:

  1. I get projects list
  2. Iterate through the list and add member on the current value

doesn't work

[psobject] $tfs = get-tfs "http://myserver:8080/tfs/defaultcollection"
[psobject] $projects = $tfs.CSS.ListA开发者_Go百科llProjects()

foreach($pro in $projects){
    $pro | add-member -membertype noteproperty -name TFS -value $tfs
    $test = $pro.TFS
}


Since you already have the $tfs object, why not just pass it with the $projects collection to whatever code you're calling after this? That way you're only dealing with it once, rather than looping over all the projects and adding the same variable to each. So something like this:

[psobject] $tfs = get-tfs "http://myserver:8080/tfs/defaultcollection"
[psobject] $projects = $tfs.CSS.ListAllProjects()

myFunction $projects $tfs
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜