Solved

Problem With Custom Function Executing Through an Imported PoSh Session

Posted on 2015-02-19
1
54 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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
In this video we show how to create a Shared Mailbox 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 Recipients >> Sha…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 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