![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Passing arguments to a function Is this happening just because it is a Monday? $args is to provide arguments to a script, but isn't it also to provide arguments to a function? What am I missing here? PS C:\> ps|where{$_.processname -eq "outlook"} Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName ------- ------ ----- ----- ----- ------ -- ----------- 1276 20 46804 8704 487 59.97 3048 OUTLOOK PS C:\> function getproc { >> $output=ps|where{$_.processname -eq "outlook"} >> $output >> } >> PS C:\> . getproc outlook Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName ------- ------ ----- ----- ----- ------ -- ----------- 1276 20 46804 8748 487 60.01 3048 OUTLOOK PS C:\> function getproc { >> $output=ps|where{$_.processname -eq "$args"} >> $output >> } >> PS C:\> . getproc outlook <--returns *nothing* PS C:\> function getproc { >> $output=ps|where{$_.processname -eq "$args[0]"} >> $output >> } >> PS C:\> . getproc outlook <--returns *nothing* PS C:\> |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Passing arguments to a function Hi Marco, > Is this happening just because it is a Monday? > > $args is to provide arguments to a script, but isn't it also to provide > arguments to a function? > > What am I missing here? Where-Object binds its own args$ variable. In order to get your function running you have to save the original $args variable first and use that instead: function getproc { $a=$args $output=ps|where{$_.processname -eq "$a"} $output } hth Max |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Passing arguments from .BAT to PowerShell script | wofat68 | PowerShell | 8 | 08-02-2008 08:40 AM |
| Passing function params by ref? | Duncan Smith | PowerShell | 1 | 01-04-2008 06:15 AM |
| Passing arguments into scripts? | Dr Herbie | PowerShell | 4 | 12-30-2006 06:13 AM |
| passing arguments | VB | PowerShell | 1 | 12-19-2006 08:23 AM |
| Executing PS1 script from CMD/SchTasks and passing arguments | Terry E Dow | PowerShell | 1 | 11-27-2006 05:45 PM |