Hi,
I am having an issue when I try to remotely run Exchange Management Shell (EMS) using the invoke-command from my powershell script. What I am trying to do is connect remotely to another server to run a powershell script that uses EMS to create a mailbox based on the argument I pass over. When I run the remote powershell script without EMS I see that the argument is passed over but it cant create the mailbox as it needs the EMS cmdlet's...however, when I connect to EMS it just hangs and does nothing. Does anybody know what could be causing this to hang? If this helps with investigation I do have the Microsoft Exchange management PowerShell snap-ins installed on my machine. Please see my script below:
$mailbox = "andreatest77"
#Modify new-user-list.txt with login name
set-content -path "\\servername\path" -value "$mailbox"
#argument in invoke-command to pass to mailbox creation script on remote server
$arg = "c:\ts\scripts\new-user-list.txt"
#Create a remote Powershell connection to Exchange 2010 and run the new-mailbox script with argument
$ScriptBlockContent = { param ($param) C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -command ". 'E:\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto" -command "C:\ts\scripts\New-O365Mailbox.ps1 c:\ts\scripts\new-user-list.txt"}
Invoke-Command -ComputerName "servername" -ScriptBlock $scriptblockcontent -argumentlist $arg