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
Technology Tips and News
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
Start by reading this: https://technet.microsoft.com/en-us/library/dd335158%28v=exchg.150%29.aspx?f=255&MSPPError=-2147217396
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
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.
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...
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
Hi Jrv,
When i am running this command i am getting sort.exe is not recognized as cmdlet, function or script file
You have to run the commands from PowerShell. You are running them from CMD.EXE
Hi Jrv,
Thank you for your support.
I am running these commands from ISE.
But eventually i have to run these commands from cmd.
HI Jrv,
if i remove sort name then nothing happens both in Powershell as well as ISE
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.
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 } } }
Hi Jrv,
Thank you for your support.
I am running above scripts.
Please let me know how i can make these work
This lone sorts by name using the Powershell sort:
$mbxs = Get-MailboxDatabase |sort name
HI Jrv,
if i remove sort name then nothing happens both in Powershell as well as ISE
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 } } }
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.
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.
Hi Jrv,
Is there any solution to above issue
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.