Powershell remoting to exchange

Welcome Forums General PowerShell Q&A Powershell remoting to exchange

This topic contains 13 replies, has 6 voices, and was last updated by

 
Participant
6 months ago.

  • Author
    Posts
  • #101470

    Participant
    Points: 1
    Rank: Member

    Is there a way to do remoting to an exchange server and be in the same configuration with no limitation as the exchange shell is providing.

  • #101482

    Participant
    Points: 190
    Helping Hand
    Rank: Participant

    Is there anything missing from using Implicit Remoting to Exchange?
    Should only be your RBAC that decide what you can do or not, as far as I know.

  • #101490

    Participant
    Points: 241
    Helping Hand
    Rank: Participant
  • #101514

    Participant
    Points: 1
    Rank: Member

    This is what I am using

    $ServerName = $env:COMPUTERNAME
    $Credential = Get-Credential
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$ServerName/PowerShell/ -Authentication kerberos -Credential $Credential
    Import-PSSession $Session

    Then, if I try to run a script from microsoft for public folder migration,
    Export-PublicFolderStatistics.ps1 -ExportFile FolderToSizeMap.csv -PublicFolderServer $servername
    I get an error : Get-PublicFolderStatistics : Missing an argument for parameter 'Server'. Specify a parameter of type 'System.Object' and try again.
    At line:1 char:59
    + @(Get-PublicFolderStatistics -ResultSize:Unlimited -Server <<<< ) + CategoryInfo : InvalidArgument: (:) [Get-PublicFolderStatistics], ParameterBindingException + FullyQualifiedErrorId : MissingArgument,Get-PublicFolderStatistics But if I ran the same command from exchange management shell it work well. This is a specific example easy to reproduce. I got plenty of this. seam to be related to serialization, deserialization, pipeline. I am really trying to use remoting on all my server, I manage more than 250. I want to avoid the need to connect in RDP, than run the exchange shell everytime. Anybody know why? The server is an Exchange 2010 in this example. A solution to this will be very appreciated. So far it doesnt seem to be possible to just load the snapin either.

  • #101529

    Participant
    Points: 265
    Helping Hand
    Rank: Contributor

    Looks like it was written to expect a -Server parameter in the script.

    If you've got the session already, you may be able to remove the parameter from the script and run it.

  • #101536

    Participant
    Points: 1
    Rank: Member

    The question, why is there so much difference in running the script in exchange shell and via a remoting session.

    Can we make adjustement to have the powershell behave like exchange shell?

  • #101541
    Jon

    Participant
    Points: 35
    Rank: Member

    This doesn't make sense to me. Presumably you are running this code from a remote machine, otherwise you wouldn't need to to do anything with importing a session. Why are you setting $servername to your local computer name?

    $ServerName = $env:COMPUTERNAME
    $Credential = Get-Credential
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$ServerName/PowerShell/ -Authentication kerberos -Credential $Credential
    Import-PSSession $Session
    

    Have you tried this?

    $Credentials = Get-Credential
    $ExSession = New-PSSession –ConfigurationName Microsoft.Exchange –ConnectionUri 'http://ExServer1.contoso.com/PowerShell/?SerializationLevel=Full' -Credential $Credentials –Authentication Kerberos
    Import-PSSession $ExSession
    
  • #101542
    Jon

    Participant
    Points: 35
    Rank: Member

    Also look at the specific error message "Specify a parameter of type 'System.Object' and try again"

    PS C:\> $pc = $env:COMPUTERNAME
    
    PS C:\> $pc | get-member
    
    
       TypeName: System.String
    
  • #101545

    Participant
    Points: 1
    Rank: Member

    Ok, Jon, can I work arround this?

  • #101548
    Jon

    Participant
    Points: 35
    Rank: Member

    Per this it looks like you have to run the export-publicfolderstatistics from the machine.

    Export-PublicFolderStatistics.ps1 This script creates the folder name-to-folder size mapping file. You'll run this script on the legacy Exchange server.

    Export-PublicFolderStatistics.psd1 This support file is used by the Export-PublicFolderStatistics.ps1 script and should be downloaded to the same location.

    What happens if you change $env:computername to the actual hostname of the exchange server holding the publicfolders?

  • #101550

    Participant
    Points: 1
    Rank: Member

    Samething.

    Export-publicfolderstatistics.ps1 might pipe to get-publicfolderstatistics at a certain point and because we are in a remote session the return might be deserialized and this is where it fail

    I have so many place where command run on exchange shell but fail in implicit remoting. It drive me crazy.

    Can we have the session behave exactly as the exchange shell?

  • #101557
    Jon

    Participant
    Points: 35
    Rank: Member

    I'm not sure how you could pipe a powershell script to a cmdlet.

    As I said in a previous discussion with you, I have never seen where the session behaves differently than the exchange shell. If you think it's different, I would recommend opening a ticket with Microsoft.

    Did you try the "serialization=full" option I posted earlier?

    • #101959

      Inactive
      Points: 0
      Rank: Member

      hi jon,

      How to run/execute a PS script on remote servers ??
      i just used like UCN path of the script,
      \\server-name\d$\Program-Files\script.ps1

      But it didn't worked !

      please help me,
      1) If i wanted to include remote server path on the script, what changes to be done?
      2) if i want to execute it directly using the path, what changes do be done ?
      i am very new to PS.
      And we need to set any server name and password ?
      Thanks in advance.

    • #101986

      Participant
      Points: 190
      Helping Hand
      Rank: Participant

      Pradeep, it's better if you start a seperate topic and not hijacking another.
      But as a quick answer you could use the powershell command "Invoke-Command".
      Just running a script from a UNC path on your local machine will run it on your machine.

      There are plenty of examples on how to use invoke-command here:
      https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/invoke-command?view=powershell-6

The topic ‘Powershell remoting to exchange’ is closed to new replies.