How to run RedistributeActiveDatabases.ps1 from a remote PowerShell

Hi Allen,

After doing all of the above including the Import-PSSession $Session, how do I execute RedistributeActiveDatabases.ps1?

This is script is not on the local RES server? Heres what I tried:

  1. Copy script files locally and run them sequentially in this PowerShell session:
  2. .\RemoteExchange.ps1

Import-LocalizedData : Cannot find PowerShell data file 'RemoteExchange.strings.psd1' in directory 'D:\scripts\Exchange\en-US\' or any parent culture directories.

At D:\scripts\Exchange\RemoteExchange.ps1:4 char:1

+ Import-LocalizedData -BindingVariable RemoteExchange_LocalizedStrings -FileName  ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (D:\scripts\Exch...ge.strings.psd1:String) [Import-LocalizedData], PSInvalidOperationException

    + FullyQualifiedErrorId : ImportLocalizedData,Microsoft.PowerShell.Commands.ImportLocalizedData

get-itemproperty : Cannot find path 'HKLM:\SOFTWARE\Microsoft\ExchangeServer\v15\Setup' because it does not exist.

At D:\scripts\Exchange\RemoteExchange.ps1:46 char:18

+ $global:exbin = (get-itemproperty HKLM:\SOFTWARE\Microsoft\ExchangeServer\v15\Se ...

+                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (HKLM:\SOFTWARE\...erver\v15\Setup:String) [Get-ItemProperty], ItemNotFoundException

    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemPropertyCommand

  1. Connect-ExchangeServer does not work. Probably needs info from RemoteExchange.ps1
  2. Try using UNC path to Exchange Server directories: PS ResServer > cd \\Mailserver1\C$\Program Files\Microsoft\Exchange Server\V14\ bin\
  3. PS Microsoft.PowerShell.Core\FileSystem::\\Mailserver1\c$\>.\RemoteExchange.ps1

get-itemproperty : Cannot find path 'HKLM:\SOFTWARE\Microsoft\ExchangeServer\v15\Setup' because it does not exist.

At \\Mailserver1\C$\Program Files\Microsoft\Exchange Server\V14\ bin\\RemoteExchange.ps1:46 char:18

+ $global:exbin = (get-itemproperty HKLM:\SOFTWARE\Microsoft\ExchangeServer\v15\Se ...

+                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (HKLM:\SOFTWARE\...erver\v15\Setup:String) [Get-ItemProperty], ItemNotFoundException

    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemPropertyCommand

get-itemproperty : Cannot find path 'HKLM:\SOFTWARE\Microsoft\ExchangeServer\v15\Setup' because it does not exist.

At \\Mailserver1\C$\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1:47 char:22

+ $global:exinstall = (get-itemproperty HKLM:\SOFTWARE\Microsoft\ExchangeServer\v1 ...

+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (HKLM:\SOFTWARE\...erver\v15\Setup:String) [Get-ItemProperty], ItemNotFoundException

    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemPropertyCommand

get-itemproperty : Cannot find path 'HKLM:\SOFTWARE\Microsoft\ExchangeServer\v15\Setup' because it does not exist.

At \\Mailserver1\C$\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1:48 char:22

+ $global:exscripts = (get-itemproperty HKLM:\SOFTWARE\Microsoft\ExchangeServer\v1 ...

+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (HKLM:\SOFTWARE\...erver\v15\Setup:String) [Get-ItemProperty], ItemNotFoundException

    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemPropertyCommand

Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///C:\Users\MyAdminAccount\bin\Microsoft.Exchange.Data.dll' or one of its dependencies. The system cannot find the file specified."

At \\s-mail11\d$\Program Files\Exchange\Bin\RemoteExchange.ps1:55 char:15

+   | ForEach { [System.Reflection.Assembly]::LoadFrom((join-path $global:exbin $_ ...

+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : FileNotFoundException

4. Even with all those errors I still tried to execute:

PS Microsoft.PowerShell.Core\FileSystem::\\Mailserver1\...c$\>. .\RedistributeActiveDatabases.ps1 -DagName D001 ShowDatabaseDistributionByServer

Add-PSSnapin : The Windows PowerShell snap-in 'Microsoft.Exchange.Management.PowerShell.E2010' is not installed on this computer.

At \\Mailserver1\C$\Program Files\Microsoft\Exchange Server\V14\Scripts\RedistributeActiveDatabases.ps1:137 char:9

+         Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010

+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (Microsoft.Excha...owerShell.E2010:String) [Add-PSSnapin], PSArgumentException

    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

Unable to find type [Microsoft.Exchange.Data.Directory.SystemConfiguration.ReplicationType]: make sure that the assembly containing this type is loaded.

At \\Mailserver1\C$\Program Files\Microsoft\Exchange Server\V14\Scripts\RedistributeActiveDatabases.ps1:147 char:1

+ $ReplicationTypeType = [Microsoft.Exchange.Data.Directory.SystemConfiguration.Re ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (Microsoft.Excha...ReplicationType:TypeName) [], RuntimeException

    + FullyQualifiedErrorId : TypeNotFound

Unable to find type [Microsoft.Exchange.Management.SystemConfigurationTasks.MoveStatus]: make sure that the assembly containing this type is loaded.

At \\Mailserver1\C$\Program Files\Microsoft\Exchange Server\V14\Scripts\RedistributeActiveDatabases.ps1:148 char:1

+ $MoveStatusType = [Microsoft.Exchange.Management.SystemConfigurationTasks.MoveSt ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (Microsoft.Excha...asks.MoveStatus:TypeName) [], RuntimeException

    + FullyQualifiedErrorId : TypeNotFound

Unable to find type [Microsoft.Exchange.Management.SystemConfigurationTasks.MountStatus]: make sure that the assembly containing this type is loaded.

At \\Mailserver1\C$\Program Files\Microsoft\Exchange Server\V14\Scripts\RedistributeActiveDatabases.ps1:149 char:1

+ $MountStatusType = [Microsoft.Exchange.Management.SystemConfigurationTasks.Mount ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (Microsoft.Excha...sks.MountStatus:TypeName) [], RuntimeException

    + FullyQualifiedErrorId : TypeNotFound

Unable to find type [Microsoft.Exchange.Data.Directory.SystemConfiguration.DatabaseCopyAutoActivationPolicyType]: make sure that the assembly containing this type is loaded.

At \\Mailserver1\C$\Program Files\Microsoft\Exchange Server\V14\Scripts\RedistributeActiveDatabases.ps1:150 char:1

+ $AutoActivationType = [Microsoft.Exchange.Data.Directory.SystemConfiguration.Dat ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (Microsoft.Excha...ationPolicyType:TypeName) [], RuntimeException

    + FullyQualifiedErrorId : TypeNotFound

Unable to find type [Microsoft.Exchange.Management.SystemConfigurationTasks.CopyStatus]: make sure that the assembly containing this type is loaded.

At \\Mailserver1\C$\Program Files\Microsoft\Exchange Server\V14\Scripts\RedistributeActiveDatabases.ps1:151 char:1

+ $CopyStatusType = [Microsoft.Exchange.Management.SystemConfigurationTasks.CopySt ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (Microsoft.Excha...asks.CopyStatus:TypeName) [], RuntimeException

    + FullyQualifiedErrorId : TypeNotFound

All of this to no avail. So what am I doing wrong?

To summarize:

  1. Cannot execute the command locally on the RES server even after copying them over from the Exchange Server;
  2. Cannot execute the scripts using the UNC path \\Mailserver1\c$\... on the Exchange Server;
June 17th, 2015 5:02am

The .net execution of exchange inbuilt scripts will work when executed via C#.

Not sure what background program this RES manager uses.

I think  you can contact RES support to execute this via RES automation manager

Free Windows Admin Tool Kit Click here and download it now
June 17th, 2015 6:56am

Hi,

If you want use Windows PowerShell to connect to Exchange server, please install the Microsoft .NET Framework 4.5 and then either the Windows Management Framework 3.0 or the Windows Management Framework 4.0.
Then run command as below: $S= New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "Http://<FQDN of CAS server> /powershell" -Credential (Get-Credential) -Authentication Basic AllowRedirection
Note: we need to specify the FQDN of an Exchange 2013 Client Access server.
At last, run Import-PSSession $Session to implement session. More details about it, for your reference: https://technet.microsoft.com/en-us/library/dd335083(v=exchg.150).aspx

For your question, please try below command:

Powershell -command ". 'c:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto;. 'c:\Program Files\Microsoft\Exchange Server\V14\Scripts\RedistributeActiveDatabases.ps1' -DagName DAG01 -BalanceDbsByActivationPreference -confirm:$false"

Thanks

June 17th, 2015 10:32pm

Hi,

Please copy RedistributeActiveDatabases.ps1 to local computer, then run below command for testing.
$s = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://<FQDN of CAS server>/PowerShell/ -Authentication Kerberos -Credential (Get-Credential)
Import-PSSession $s

As you can see here, the Exchange Management Shell commands are imported into our local PowerShell session and listed in under the exported commands column.

Then use Invoke-Command to run script, sample as below:
Invoke-Command -Session $s -FilePath C:\RedistributeActiveDatabases.ps1

Meanwhile, we can use Exchange management components Tool then use command as my initial reply.

Thanks

Free Windows Admin Tool Kit Click here and download it now
June 17th, 2015 11:15pm

Thanks Sathish,

I did read about that on the site I mentioned in my initial post, however since I'm not a programmer, it's a bit difficult to understand how.

RES will be contacted today.

June 18th, 2015 1:46am

Hi Allen,

I do see a minor difference between what you posted and what I tried.

Today i'll give it a shot and get back in about 4 - 6 hours.

Tnx

Free Windows Admin Tool Kit Click here and download it now
June 18th, 2015 1:48am

Hi All,

Is there a way to run %ExchangeInstallPath%\Scripts\RedistributeActiveDatabases.ps1 from a remote machine?

Background:

Within our organization all scripts are centralized using RES Automation Manager. Of course this is a somewhat controversial issue since all versions of windows comes with Task Scheduler already pre-configured to run 70 jobs on our exchange server (Get-ScheduledTask | where {$_.State -ne 'Disabled'} | measure).

Its about all the tasks scheduled by the admins. Company policy is use RES AM. So I am struggling with 3 scripts, Test-ExchangeServerHealth.ps1,  Purge-LogFiles.1.5 and the most important %ExchangeInstallPath%\Scripts\RedistributeActiveDatabases.ps1.

If anyone is able to run this from a Remote Server (RES) in a PowerShell session using either:

  1. $creden=Get-Credential domain\user ** with **  Enter-PSSession -ComputerName mailserver1 -Credential $cred  or
  2. $s = new-pssession -configurationname microsoft.exchange -connectionuri "http:// mailserver1.dom.local/PowerShell/" -authentication Kerberos  ** with ** Import-PSSession $s 2>&1 | out-null

I am really curious to see how this is done for the elusive RedistributeActiveDatabases.ps1 which makes all sorts of .NET/Exchange calls or refer other resource files, and seem to be dependent on other parameters which most likely blocks the successful completion of the remote script. See also http://blogs.msdn.com/b/dhruvkh/archive/2012/05/08/automating-execution-of-built-in-exchange-2010-ps1-scripts-through-net.aspx

Any ideas?

Tnx

Timotatty

June 18th, 2015 3:27am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics