Exchange Powershell return value from Get-command to variable.
hi
i trying create powershell-script our monitoring-software.
the script supposed establish connection our exchange-server mgmt-shell , execute command:
"get-mailboxdatabasecopystatus"
i have connection in place, missing knowledge of how return result of command script, can pass our monitoring-software.
(the script take 2 parameters - host , command eg. exch01.domain , get-mailboxdatabasecopystatus).
current code:
$statusalive = "scriptres:host 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 empty" exit } if (!$args[1]) { echo $statusunknown"command parameter empty" exit } #> $session = new-pssession -configurationname microsoft.exchange -connectionuri http://$host/powershell -credential $cred import-pssession $session $command remove-pssession $session
now, how "catch" value of executed command , return variable in script?
best regards,
soren
for starters, $host is bad choice variable because in use (see about_automatic_variables for more information). recommend using $computername instead.gs make more user friendly (see about_functions_advanced_parameters for more information).
param ( [string]$computername, [scriptblock]$command )
calling $command not other showing in actual variable. need invoke script in order happen. if use example above parameters, have invoke scriptblock using invoke().
$returnvalue = $command.invoke()
if specific command, recommend typing command out after implicit remoting.
boe prox
blog | twitter
poshwsus | poshpaig | poshchat | posheventui
powershell deep dives book
Windows Server > Windows PowerShell
Comments
Post a Comment