开发者

Add-member in iteration doesn't work in PowerShell

开发者 https://www.devze.com 2023-01-31 07:15 出处:网络
Here is the code: I get projects list Iterate through the list and add member on the current value doesn\'t work

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

精彩评论

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