C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -nologo -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; c:\Scripts\script.ps1"
If you don't want to use a powershell script you can embed your code within this parameter. You might find this method useful for short scripts or one-liners. For example, to list the databases mounted on a specific server, consider the following:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -nologo -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; Get-MailboxDatabase | where {$_.Server -eq "mailserver"}
To schedule PowerShell scripts one would not require Exchange tools installed locally - PowerShell v2 is necessary, though. Use implicit remoting to import the Exchange Management Shell cmdlets from a specific server. Consider the following:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -nologo -command "$s = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://fab-ex2.fabrikam.local/PowerShell/ -Authentication Kerberos; Import-PSSession $s; Get-MailboxDatabase | where {$_.Server -eq "mailserver"}
No comments:
Post a Comment