Issue with running redistributeactivedatabases.ps1 in new-pssession

Hi,

I am stuck with the issue to run redistributeactivedatabases.ps1 in new-pssession.

Is there any best pratice or some other script to redistribute the mailbox databases using new-pssession

April 21st, 2015 7:18am

Hi Jrv,

Thanks for your reply.

My issue is i am trying to run redistributeactivedatabases.ps1 but i have to run this in new-pssession as this needs to be run using JP1 job which doesnot have 64-bit client so to overcome this issue i am using new-psssession.

So, below is the command which i am running

C:\Users\user>"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
-command "$s= New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri
http://Exchservername/PowerShell/ -Authentication Kerberos ; Import-PSsession $s; "C:\Failback.ps1"

Wheras Failback.ps1 is below script

$mbxs = Get-MailboxDatabase | Sort Name
ForEach($mbx in $mbxs)
{
$MBdb
=$mbx.Name $ServerHosting=$mbx.Server.Name
if($mbx.activationPreference.value -eq 1)
{
If ($ServerHosting -ne $ActivationPreference.Key.Name) 
{
Move-ActiveMailboxDatabase $MBdb -ActivateOnServer $ActivationPreference.Key.Name -confirm:$False 
}
}
}

But its not working as nothing happens

April 21st, 2015 8:26am

I don't see what you are asking.  The second script has little to do with the original question. It also has syntax errors.

It should look like this:

$mbxs = Get-MailboxDatabase | Sort Name 
ForEach($mbx in $mbxs){ 
    $MBdb=$mbx.Name 
    $ServerHosting=$mbx.Server.Name 
    if($mbx.activationPreference.value -eq 1) {
        If ($ServerHosting -ne $ActivationPreference.Key.Name){
            Move-ActiveMailboxDatabase $MBdb -ActivateOnServer $ActivationPreference.Key.Name -confirm:$False  
        }
    }
}

To discover what is happening you need to place trace messages in script.

Free Windows Admin Tool Kit Click here and download it now
April 21st, 2015 8:43am

Hi Jrv,

Thanks for sharing the script.

I am trying to run this script command prompt.

C:\Users\user>"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
-command "$s= New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri
http://Exchservername/PowerShell/ -Authentication Kerberos ; Import-PSsession $s; "C:\Failback.ps1"

C:\failback.ps1 is the above script. but i am getting only below warning and nothing is happening.

Warning: Some imported command names include unapprovedd verbs which might
make them less discoverable. Use the Verbose parameter for more details or type 
get-verb to see the lost of approved verbs.

Basically what is am trying to do is to rebalance my exchange mailbox databases after rebooting them from JP1. But JP1 is not able to run the Exchange powershell as application is 32-bit. To over come that issue i am using New-PSSession and trying run this script in that session but it is not working.

I am able to failback the database if i add static options which is not acceptable by my bosses. So, please help...

April 21st, 2015 9:02am

What you are doing makes little sense to me.

To remote a scrip we would do this:

#
$s=New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri  http://Exchservername/PowerShell/ -Authentication Kerberos
Invoke-Command -File C:\Failback.ps1 -Session $s



Free Windows Admin Tool Kit Click here and download it now
April 21st, 2015 9:11am

Hi Jrv,

When i am running this command i am getting sort.exe is not recognized as cmdlet, function or script file

April 21st, 2015 9:43am

You have to run the commands from PowerShell. You are running them from CMD.EXE

Free Windows Admin Tool Kit Click here and download it now
April 21st, 2015 9:46am

Hi Jrv,

Thank you for your support.

I am running these commands from ISE.

But eventually i have to run these commands from cmd.

April 21st, 2015 9:50am

HI Jrv,

if i remove sort name then nothing happens both in Powershell as well as ISE


Free Windows Admin Tool Kit Click here and download it now
April 21st, 2015 10:00am

You are still being way to vague.
April 21st, 2015 10:05am

Hi Jrv, I ran this script in powershell as well as ISE and I am getting sort.exe is not recognized. If I remove sort name from the script then there is no error but nothing happens
Free Windows Admin Tool Kit Click here and download it now
April 21st, 2015 10:12am

Hi Jrv, Is there any solution.
April 21st, 2015 11:15am

Solution to what.  Your question is way too vague.  Post the exact script that you are running.  Just posting comments saying it doesn't work or posting an error with no script is not very helpful.

Free Windows Admin Tool Kit Click here and download it now
April 21st, 2015 11:19am

Hi Jrv,

$s= New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://Exchangeserver/PowerShell/ -Authentication Kerberos
Invoke-Command -File "C:\Users\Lanid\Desktop\script.ps1" -Session $s

$mbxs = Get-MailboxDatabase | sort name
ForEach($mbx in $mbxs){ 
    $MBdb=$mbx.Name 
    $ServerHosting=$mbx.Server.Name 
    if($mbx.activationPreference.value -eq 1) {
        If ($ServerHosting -ne $ActivationPreference.Key.Name){
            Move-ActiveMailboxDatabase $MBdb -ActivateOnServer $ActivationPreference.Key.Name -confirm:$False 

        }
    }
}



April 21st, 2015 11:29am

Hi Jrv,

Thank you for your support.

I am running above scripts.

Please let me know how i can make these work

Free Windows Admin Tool Kit Click here and download it now
April 21st, 2015 12:11pm

This lone sorts by name using the Powershell sort:

$mbxs = Get-MailboxDatabase |sort name

April 21st, 2015 1:44pm

HI Jrv,

if i remove sort name then nothing happens both in Powershell as well as ISE


  • Edited by Nothing 123 Tuesday, April 21, 2015 1:58 PM
Free Windows Admin Tool Kit Click here and download it now
April 21st, 2015 1:58pm

Hi Jrv,

$s= New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://Exchangeserver/PowerShell/ -Authentication Kerberos
Invoke-Command -File "C:\Users\Lanid\Desktop\script.ps1" -Session $s

$mbxs = Get-MailboxDatabase | sort name
ForEach($mbx in $mbxs){ 
    $MBdb=$mbx.Name 
    $ServerHosting=$mbx.Server.Name 
    if($mbx.activationPreference.value -eq 1) {
        If ($ServerHosting -ne $ActivationPreference.Key.Name){
            Move-ActiveMailboxDatabase $MBdb -ActivateOnServer $ActivationPreference.Key.Name -confirm:$False 

        }
    }
}



  • Edited by Nothing 123 Tuesday, April 21, 2015 3:27 PM
April 21st, 2015 3:27pm

Hi Jrv, Script runs fine if I run it using exchange management shell but issue is from the server I am running this script it does not have exchange tools
Free Windows Admin Tool Kit Click here and download it now
April 21st, 2015 4:01pm

Sorry.  I have no idea what you are trying to ask or say.  You have made so many conflicting statements that I can no longer tell what you are asking. 

You cannot run an Exchange command without connecting to an Exchange server either with the shell or using a remote session.

Start by reading about how to use the Exchange session to remotely access Exchange.

You can only run allowed commands in an exchange session.  You can have a hybrid environment if you import the session.

Search for blogs that explain how the is used.

April 21st, 2015 4:18pm

Hi Jrv,

I am sorry for not being very clear.

Also i know what i am trying is not very sane but i cannot help it as i got order that i have to achive this.

Below are the exact suitation.

We have JP1 server (Automation) which we use to reboot/failover/failback.

I have to automate failover and failback scripts. I am able to achive failover part as it is simple command

Move-ActiveMailboxDatabase -server servername

and it is working.

For failback and automatic rebalance mailbox database according to the activation preference i am using below script which i have to run using cmd.

$mbxs = Get-MailboxDatabase | sort name
ForEach($mbx in $mbxs){
    $MBdb
=$mbx.Name
    $ServerHosting
=$mbx.Server.Name
   
if($mbx.activationPreference.value -eq 1) {
       
If ($ServerHosting -ne $ActivationPreference.Key.Name){
           
Move-ActiveMailboxDatabase $MBdb -ActivateOnServer $ActivationPreference.Key.Name -confirm:$False

       
}
   
}
}

But the problem i am getting is that script is not working when i am running this in cmd or in powershell.

But if i run the same script on Exchange server using Exchange Management shell then there are no issues.

So, i need your help so that i can run above script using cmd in new-pssession.

Hopefully i am able to make some sense now.

Free Windows Admin Tool Kit Click here and download it now
April 21st, 2015 10:43pm

Hi Jrv,

Is there any solution to above issue

April 22nd, 2015 2:16am

Sorry, but you are asking two many different things, none of which make sense.

I think you are going to need to hire someone to help you in your own language.

Free Windows Admin Tool Kit Click here and download it now
April 22nd, 2015 8:30am

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

Other recent topics Other recent topics