0

OK, I looked, and read, then looked some more... For the life of my I cannot figure out why my object will not return from my function! This is contained in a module within a separate file being called from another script. Everything is assigned properly BUT once this function loses scope so do the variables... How do I return the wiStore object OR set it so it does not lose scope after words.

Edit: Please note that nothing is returned, I can see the variable set in the debugger but magically it goes null after the function has finished executing.

function Get-WiStore
{
    param
    (
        $CollectionUrl
    )

    Add-TfsReferences
    $tfsUri = New-Object System.Uri $CollectionUrl
    $tfProjectCollection = New-Object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection $tfsUri
    #WHY DO YOU DISAPEAR!!!!?!?!?!?!?!?!?! :'(
    $wiStore = New-Object Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore $tfProjectCollection
}



function Add-TfsReferences
{
    #my *.dll references       
}
TacoMaster6000
  • 304
  • 3
  • 12

2 Answers2

0

If you just need to return $wiStore there are two ways you can do it. The first would be to just call it at the end of your function, the second would be to use the RETURN keyword to explicitly tell powershell to return the value.

return $wistore
Mike Garuccio
  • 2,588
  • 1
  • 11
  • 20
0

I have solved the issue myself, the problem was my references were failing but power shell failed to notify me. If you require references for a module then you should create a Module Manifest. Also, I removed the variable $wiStore and simply returned a new object.

function Get-WiStore
{
    param
    (
        $CollectionUrl
    )

    $tfsUri = New-Object System.Uri $CollectionUrl
    $tfProjectCollection = New-Object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection $tfsUri
    New-Object Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore $tfProjectCollection
}

Please see an answer to my other question for more details: https://stackoverflow.com/a/38246932/3812871

Community
  • 1
  • 1
TacoMaster6000
  • 304
  • 3
  • 12