N
N
NewDevLab2020-04-23 14:39:21
PowerShell
NewDevLab, 2020-04-23 14:39:21

Displaying results inside a function?

function TestFunc1() {
  Get-NetAdapter	
  #return $null
}
function TestFunc2() {
  $ret2 = TestFunc1
}
TestFunc2


How in such a situation to get the output of Get-NetAdapter. As I understand it, it somehow returns higher up the stack and terminates on $ret2. Even if it is forced to return a different value from TestFunc1. It is better not to touch TestFunc1.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
2
2CHEVSKII, 2020-04-23
@NewDevLab

Something is not clear why you need such pasta, but you can get the output on the screen through Out-Host:
Get-NetAdapter | Out-Host

C
Crovax, 2020-05-19
@Crovax

TestFunc2 does not display anything because it only assigns $ret2, and this operation does not display anything on the screen.
If you want the result to be visible, then you need to "show" the contents of the variable:

function TestFunc2() {
  $ret2 = TestFunc1
  $ret2
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question