Solved

Problem With Custom Function Executing Through an Imported PoSh Session

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Local Continuous Replication is a cost effective and quick way of backing up Exchange server data. The following article describes the steps required to configure Local Continuous Replication. Also, the article tells you how to restore from a backup…
A procedure for exporting installed hotfix details of remote computers using powershell
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…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

708 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now