Solved

Problem With Custom Function Executing Through an Imported PoSh Session

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
In-place Upgrading Dirsync to Azure AD Connect
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

680 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