![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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) |
| | 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 | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Passing arguments to external command through PS | PowerShell | |||
| Need help - passing string arguments with quotes | PowerShell | |||
| Passing arguments from .BAT to PowerShell script | PowerShell | |||
| Passing arguments into scripts? | PowerShell | |||
| passing arguments | PowerShell | |||