Announcement

Collapse
No announcement yet.

A simple Powershell Question

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • A simple Powershell Question

    Dear peeps,

    I have located the following script to list all the receive connectors with the remoteIpRanges.

    I have tried but failed, I really want the output to be exported to a csv file.

    Does anyone know how I could amend the following code to accommodate this?


    $RcvConnector = Get-ReceiveConnector

    foreach ($Connector in $RcvConnector)

    {
    $Connector
    $RemoteIpRange = $connector.RemoteIpRanges
    $RemoteIpRange
    }

  • #2
    Re: A simple Powershell Question

    Have you tried appending
    $RcvConnector|export-csv <filename>

    or
    export-csv <filename> $RcvConnector

    ?
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment


    • #3
      Re: A simple Powershell Question

      Thanks Ossian,

      I tried this:

      Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
      $RcvConnector = Get-ReceiveConnector

      foreach ($Connector in $RcvConnector)

      {
      $Connector
      $RemoteIpRange = $connector.RemoteIpRanges
      $RemoteIpRange
      $RCvConnector |export-csv "C:\test.csv"
      }

      Which worked to some extent, so thanks! however the RemoteIpRanges lists the following in the spreadhseet:

      Microsoft.Exchange.Data.MultiValuedProperty`1[Microsoft.Exchange.Data.IPRange]

      So ideally I am going to need that converted to IP's. I know usually I could run the | select command and just return certain items. However I can't seem to do this with the current script.

      I just ideally want the name of the receive connector and RemoteIPRange.

      If you have any ideas on this, that would be great!

      Comment


      • #4
        Re: A simple Powershell Question

        I have worked part of it out

        Get-ReceiveConnector -identity "ConnectorNAME" | Out-File "C:\newtest.txt"

        $rcv=(Get-ReceiveConnector "CONNECTORNAME.RemoteIPRanges| out-file -append "C\newtest.txt"


        I just need to wrap this up so it can query all the Connectors.

        Comment


        • #5
          Re: A simple Powershell Question

          How about:

          Code:
          {
          $Connector
          $RemoteIpRange = $connector.RemoteIpRanges
          $RemoteIpRange
          $RCvConnector.ToString() |export-csv "C:\test.csv"
          }
          I have not tested this but it should give you the results in a string instead of an object (which is why you were getting the "Microsoft.bla.bla.etc")
          Regards,
          Jeremy

          Network Consultant/Engineer
          Baltimore - Washington area and beyond
          www.gma-cpa.com

          Comment


          • #6
            Re: A simple Powershell Question

            So disregard my last post. I reread what you're looking for.

            So are you wanting to get just the IP addresses or do you want the full information of the remote IPs? The reason I ask is because there can be several entries and several different formats the remote IPs can be in. Here's a script that will dump all the Receive connectors with remote IPs (which I think would be all of them) to a text file:

            Code:
            $RcvConnector = Get-ReceiveConnector
            
            foreach ($Connector in $RcvConnector)
            
            { 
              If ($Connector.RemoteIpRanges -ne $null)
              {
                $Connector.Name  |out-file -append "C:\test.csv"
                $Connector.RemoteIpRanges  |out-file -append "C:\test.csv"
              }
            }
            Regards,
            Jeremy

            Network Consultant/Engineer
            Baltimore - Washington area and beyond
            www.gma-cpa.com

            Comment


            • #7
              Re: A simple Powershell Question

              Hi Jeremy,

              I will give this a go and report back, thank you.

              P.S I was just after a script to get a list of the Receive connectors. Export the data with the name of the receive connector and the IPRanges for each one to a tezxt file or CSV


              Eg

              ReceiveConenctor 1
              IP Ranges


              receiveConenctor2
              IPRanges

              Comment


              • #8
                Re: A simple Powershell Question

                Ok it works, thats fantatsic Thanks!

                I had to use the .txt extension rather than csv otherwise I got the multivalue information rather than the IP addresses.

                I may look at adding some more details to the output, to make it more useful (If I can figure it out)

                Update: I have added the permissions now for each connector, which outputs all the information I require.

                How simple is it to add a heading for each part of the output? for Example:

                Name:
                Receive Connector 1
                RemoteIPRanges

                Name:
                Receive Connector 2
                RemoteIPRanges


                Cheers

                Pdog
                Last edited by Pdog; 20th January 2012, 09:14.

                Comment


                • #9
                  Re: A simple Powershell Question

                  I have madet he script a bit simpler now. From the Shell I just use:
                  \.scriptname | out-file c:\output.txt

                  This works well, However one of my connectors has a lot of addresses and I can't seem to use any formatting with this script put each IP address on a single line. So I will continue to work on that. Apart from that it works!

                  Thanks to everyone for their help.










                  $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 | fl
                  " "
                  " "
                  "PermissionGroups: " + $Connector.PermissionGroups
                  " "
                  " "
                  " "
                  "================================================= ======= "
                  }

                  Comment


                  • #10
                    Re: A simple Powershell Question

                    Looks good. Thanks for sharing.
                    Regards,
                    Jeremy

                    Network Consultant/Engineer
                    Baltimore - Washington area and beyond
                    www.gma-cpa.com

                    Comment

                    Working...
                    X