powershell - How can I create a log that is usable for output, but still allow for output and input in the console -


function logwrite {    out-file -append "scan.log" }  function test-isadmin  {     if (-not ([security.principal.windowsprincipal] [security.principal.windowsidentity]::getcurrent()).isinrole(     [security.principal.windowsbuiltinrole] "administrator")) {     write-warning "you not have administrator rights run script!`nplease re-run script administrator!"         break     } }  function restart-saned {     get-service -name tbs | logwrite     stop-service -name tbs     start-service -name tbs } 

above snippet of code trying use. cannot "get-service" line output log file. when not create function , instead use:

get-service -name tbs | out-file -append "scan.log" 

logging works correctly , output. there way create function simplify logging in powershell?

you need re-pipe special $input variable,

function logwrite {    $input | out-file -append "scan.log" } 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -