Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function parameter always empty why?

Can someone tell me, why this function call does not work and why the argument is always empty ?

function check([string]$input){
  Write-Host $input                             #empty line
  $count = $input.Length                        #always 0
  $test = ([ADSI]::Exists('WinNT://./'+$input)) #exception (empty string) 
  return $test
}

check 'test'

Trying to get the info if an user or usergroup exists..

Best regards

like image 468
Keine-Ahnung Avatar asked May 30 '15 13:05

Keine-Ahnung


1 Answers

$input is an automatic variable.

https://technet.microsoft.com/ru-ru/library/hh847768.aspx

$Input

Contains an enumerator that enumerates all input that is passed to a function. The $input variable is available only to functions and script blocks (which are unnamed functions). In the Process block of a function, the $input variable enumerates the object that is currently in the pipeline. When the Process block completes, there are no objects left in the pipeline, so the $input variable enumerates an empty collection. If the function does not have a Process block, then in the End block, the $input variable enumerates the collection of all input to the function.

like image 96
Andrew Semenov Avatar answered Sep 21 '22 22:09

Andrew Semenov