Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 57
  • Last Modified:

Problem With Custom Function Executing Through an Imported PoSh Session

I have a function, and inside there's another function like below:

Function Get-CAServersForSite
{

Param(
     [Parameter(Mandatory=$true, Position=0)]$Site,
     [Parameter(mandatory=$false,Position=1)]$Version = 14
     )#End Parameter Block...

$Return = `
Get-ExchangeServer |
Where{
     $_.ServerRole -match "ClientAccess" -and `
     $_.Site.Name -eq $Site              -and `
     $_.AdminDisplayVersion.Major -eq $Version
     } |
ForEach{$_.Name}

Return $Return

} #End Function Get-CAServerForSite

I have an RBAC enabled user importing a session that has all the necessary underlying commands.  That import is being done by exporting the session as a regular module on disk then loading it through the profile script.

This function has worked perfectly for a very long time, but when it is used through the implicit session it returns null.  I did some investigation and realized that in the session a string is returned instead of an object.  OK no problem I'll just parse the string to get the value I'm looking for like below:

Function Get-CAServersForSite
{

Param(
     [Parameter(Mandatory=$true, Position=0)]$Site,
     [Parameter(mandatory=$false,Position=1)]$Version = 14
            ) #End Parameter Block...

$Return = `
Get-ExchangeServer |
Where{
     $_.ServerRole -match "ClientAccess" -and `
       $_.Site.SubString($_.Site.LastIndexOf("/") + 1) -eq $Site -and `
       $_.AdminDisplayVersion.Major -eq $Version
       } |
ForEach{$_.Name}

Return $Return

} #End Function Get-CAServerForSite

This works fine on the console, but as soon as I pump everything through the master function again it returns null.  What am I missing here?
0
nashiooka
Asked:
nashiooka
1 Solution
 
nashiookaAuthor Commented:
This problem is resolved I rewrote the code to avoid the troubled function.
0

Featured Post

Ready for your healthcare security check-up?

In the past few years, healthcare organizations have become a prime target for advanced attacks. Does your organization have what it needs to defend itself? Schedule your healthcare security check-up today and download our free Healthcare Security Resource Kit today!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now