Hi
I am trying to create a powershell-script for our monitoring-software.
The script is supposed to establish a connection to our exchange-server mgmt-shell and execute this command:
"Get-MailboxDatabaseCopyStatus"
I have the connection in place, but am missing the knowledge of how to return the result of the command to my script, which I can then pass to our monitoring-software.
(The script take 2 parameters - host and command eg. exch01.domain and Get-MailboxDatabaseCopyStatus).
Current code:
$statusAlive = "ScriptRes:Host is alive:" $statusDead = "ScriptRes:No answer:" $statusUnknown = "ScriptRes:Unknown:" $statusNotResolved = "ScriptRes:Unknown host:" $statusOk = "ScriptRes:Ok:" $statusBad = "ScriptRes:Bad:" $statusBadContents = "ScriptRes:Bad contents:" $pass = cat C:\securestring.txt | convertto-securestring $Cred = new-object -typename System.Management.Automation.PSCredential -argumentlist "domain\administrator",$pass $host = $args[0] $command = $args[1] <# if (!$args[0]) { echo $statusUnknown"Host parameter is empty" exit } if (!$args[1]) { echo $statusUnknown"Command parameter is empty" exit } #> $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$host/powershell -Credential $cred Import-PSSession $session $command Remove-PSSession $session
Now, how do I "catch" the value of the executed command and return it to a variable in the script?
Best Regards,
Soren