Solved

Problem With Custom Function Executing Through an Imported PoSh Session

Posted on 2015-02-19
1
53 Views
Last Modified: 2015-02-24
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
Comment
Question by:nashiooka
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 10

Accepted Solution

by:
nashiooka earned 0 total points
ID: 40628130
This problem is resolved I rewrote the code to avoid the troubled function.
0

Featured Post

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
In this video we show how to create an Address List in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Organization >> Ad…
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question