powershell - Suppress content listing from invoke-command with filepath -


after writing powershell script build list of servers , perform maintenance activity on each, decided split 2 parts. inner script, call scriptb, thing on server name passed in; outer script, scripta, builds list of servers , runs scriptb on each. idea scripta someday able run choice of scripts -- scriptb or scriptc, instance -- against each server, depending on control parm. , maintenance script (b or c) can run itself, i.e. passing name of target server.

i call scriptb scripta using invoke-command -filepath option, , appears work fine. except that, each iteration, content of scriptb appears in output. if call 3 times have 3 copies of scriptb in output. have write-output statements in scriptb explain what's going on, messages hard spot amid noise.

i have tried assigning output variable, instance:

$eatthis = invoke-command -computername sqlbox -filepath c:\dba\scriptb.ps1

and quiet, variable ate output along unwanted listings ... , large enough prefer not parse it. tried reading on streams, didn't promising direction either. @ point i'm ready convert scriptb function , give benefits of having standalone script, if knows easy way suppress listing of invoke-command scriptblock specified via -filepath helpful.

alternatively, way phrase google welcome. search terms "listing," "echo," , "suppress" aren't getting me need.

convert scripts advanced functions. can stored in separate files , dotsourced in master script. loads function , makes available.

e.g.

c:\scripts\complicatedprocessfunctions.ps1  

(which contains function run-functionb {...} , later function runfunctionc {...})

then call function

$dataresults = runfunctiona 

or even

$dataresults += runfunctiona 

if you're running within loop , building collection of results. sounds might be.

make sure each function returns data object or collection of objects. custom powershell object of creation.

the master script processes results.

i recommend get-help about_advanced_functions, scripting guys blog, , powershell scripting games website information on how build advanced functions, , how right.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -