Add-member in iteration doesn't work in PowerShell
Here is the code:
- I get projects list
- 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
精彩评论