Page 1 of 2 12 LastLast
Results 1 to 10 of 11
Like Tree1Likes

Thread: Powershell Receive Connector Script

  1. #1
    Member
    Join Date
    Jan 2012
    Posts
    14

    Powershell Receive Connector Script

    Hello,

    I have created a simple Powershell script to list the Receive Connectors on a particular server.

    $Server = get-ExchangeServer -Identity "ServerName"
    $RcvConnector = Get-ReceiveConnector -server "ServerName"


    foreach ($Connector in $RcvConnector)

    {
    "================================================= ======"
    "Server Name: " +$Server.Name
    " "
    " "
    "Connector Name: " +$Connector.Name
    " "
    " "
    "IP Ranges: " + $Connector.RemoteIpRanges
    " "
    " "
    "PermissionGroups: " + $Connector.PermissionGroups
    " "
    " "
    " "
    "================================================= ======= "
    }


    I can output the script by using the out-file command from the Shell.

    I have one problem though, one of the connectors has a lot of RemoteIPs. When I run the script these IP addresses are not on a single line, they are wrapped which in turn makes hard to read and if I ever needed them would take a long time to decipher!

    I have tried adding | fl at the end of this line: "IP Ranges: " + $Connector.RemoteIpRanges | fl

    This makes no difference. Does anyone have an idea how I can force the output to have an IP address on a single line (rather than it being wrapped?)


    Cheers

    Pdog

  2. #2
    Exchange Server Pro
    Join Date
    Oct 2011
    Location
    Brisbane, Australia
    Posts
    425
    Quick and dirty solution:

    Code:
    $Server = get-ExchangeServer -Identity "servername"
    $RcvConnector = Get-ReceiveConnector -server $Server
    
    
    foreach ($Connector in $RcvConnector)
    
    {
       "======================================================="
       "Server Name: " +$Server.Name
       " "
       " "
       "Connector Name: "  +$Connector.Name
       " "
       " "
       "IP Ranges: "
       foreach ($ip in $Connector.RemoteIPRanges)
       {
     	$ip
       }
       " "
       " "
       "PermissionGroups: " + $Connector.PermissionGroups
       " "
       " "
       " "
       "======================================================== "
    }
    When you run that you'll probably notice the new problem it potentially creates for you :-)
    albertwt likes this.
    Paul Cunningham
    MCTS/MCITP Exchange Server 2007/2010

    Website: ExchangeServerPro.com
    Connect: Twitter | Google+ | Linkedin

  3. #3
    Member
    Join Date
    Jan 2012
    Posts
    14
    Hi Paul,

    That worked great! thanks for the reply! I inspected the txt file afterwards and could not see any new problem!

    Cheers for the additional code. Hopefully others will find it useful.

    P.S I currently keep all my Powershell commands in a notepad file, with some text reminding me of what each script does.

    Can anyone recommend an editor whereby the comments can be in a different colour?

    I know there is the PowerGUI or Notepad++ I just wondered what other people use to store their scripts?

    I did try Notepad++ but I could not get the comment lines to appear in a different colour, maybe I'll give it another whirl when I have 5 minutes!.
    Last edited by Pdog; 01-23-2012 at 06:54 AM. Reason: added text

  4. #4
    Exchange Server Pro
    Join Date
    Oct 2011
    Location
    Brisbane, Australia
    Posts
    425
    I use PowerGUI every day, it is very good. Highly recommended.
    Paul Cunningham
    MCTS/MCITP Exchange Server 2007/2010

    Website: ExchangeServerPro.com
    Connect: Twitter | Google+ | Linkedin

  5. #5
    Member
    Join Date
    Oct 2011
    Location
    Melbourne, Australia
    Posts
    51
    I too use PowerGUI every day, it's truly a fantastic product. I have my scripts synced to my dropbox (with the %dropbox%\scripts\ path as my default location in PowerShell). I use the format:
    %dropbox%\scripts\Get-Whatever\Get-Whatever.ps1 for scripts
    %dropbox%\scripts\Modules\ModuleName\Module.psm1 for modules
    etc.

    Also, have a look at the "ExpandProperty" parameter on the "Select-Object" cmdlet, as it may prove useful in this situation.
    Chris Brown
    MCTS Exchange Server 2010

    Personal Blog | PowerShell Down Under
    Twitter | LinkedIn | AuTechHeads

  6. #6
    Member
    Join Date
    Jan 2012
    Posts
    14
    Thanks for the information, I have started to use PowerGUI, I have created a folder in the Administrative Console and placed my scripts under this folder. I have six scripts listed under this folder, and I would like to take a copy of them. I have looked in the following directories:

    C:\Documents and Settings\Name\Application Data\Quest Software\PowerGUI\Scripts
    C:\Program Files\PowerGUI

    Any ideas?

  7. #7
    Member
    Join Date
    Oct 2011
    Location
    Melbourne, Australia
    Posts
    51
    Pdog,

    I'm not sure where (if anywhere) PowerGUI leaves its scripts as files. I use the PowerGUI Script Editor for editing my scripts, the console a bit less. I'd suggest leaving your scripts sitting on the file system then just copy/reference inside PowerGUI Console.
    Chris Brown
    MCTS Exchange Server 2010

    Personal Blog | PowerShell Down Under
    Twitter | LinkedIn | AuTechHeads

  8. #8
    Member
    Join Date
    Jan 2012
    Posts
    14
    Sounds Like a Plan, Thanks. I was also experimenting with some of Paul's script in PowerGUI, took me about 30 minutes to realise I had enable the "Messages" view, in order to see the output

    BTW Paul I see the issue with the script, The script in its current state will only work with the server name specified. It won't work if the server is not specified.
    Last edited by Pdog; 02-01-2012 at 08:49 AM.

  9. #9
    Member
    Join Date
    Jan 2012
    Posts
    14
    Here is my completed script,

    Hopefully someone else will find it useful

    Code:
    $Server = get-ExchangeServer | where {$_.ServerRole -ne "Mailbox"}
    
    $RcvConnector = $server | ForEach-Object {Get-ReceiveConnector}
    
    foreach ($Connector in $RcvConnector)
    
    {
       "======================================================="
       "Server Name: "  +$Connector.Server
       " "
       " "
       "Connector Name: "  +$Connector.Name
       " "
       " "
       "IP Ranges: "
       foreach ($ip in $Connector.RemoteIPRanges)
       {
     	$ip
       }
       " "
       " "
       "PermissionGroups: " + $Connector.PermissionGroups
       " "
       " "
       " "
       "======================================================== "
    }

  10. #10
    Member
    Join Date
    Oct 2011
    Location
    Melbourne, Australia
    Posts
    51
    Looks good! Glad you got it sorted out


    Edit:
    One thing that may interest you:

    Code:
    PS> "hello`nthis is on a new line"
    hello
    
    this is on a new line
    Placing `n in a string inserts a line break. Instead of having multiple lines of " ", you could simply use: "`n`n`n".
    Chris Brown
    MCTS Exchange Server 2010

    Personal Blog | PowerShell Down Under
    Twitter | LinkedIn | AuTechHeads

 

 
Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT. The time now is 03:14 PM. Powered by vBulletin® Version 4.1.10
Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.
SEO by vBSEO 3.6.0 vBulletin skins by CompleteVB