PoshCode Logo PowerShell Code Repository

AS function by karl prosser 34 months ago
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1019"></script>download | new post

AS function. simple wrapper for generating the hashtables that select-object uses

  1. #region setup AS function
  2. function new-selectexpression
  3. {
  4. if ($args.count -eq 1) { $theargs = $args[0] } else {$theargs= $args }
  5. if ($theargs.count -gt 1)
  6. {
  7. for($loop=0;$loop -lt ($theargs.count-1);$loop+=2)
  8.  {
  9.   @{Name=$theargs[$loop];Expression=$theargs[$loop+1]}
  10.  }
  11. }
  12. if (!($theargs.count % 2) -eq 0) {@{Name=$input[$input.count-1];Expression= invoke-Expression "{}" } }
  13. }
  14. set-Alias as  new-selectexpression
  15. #endregion
  16. #Examples
  17. #Select (as theprocess ,name ,
  18. #            "CPU" , {$_.privatememorysize/ 1KB} ,
  19. #                       "memory KB" , {$_.privatememorysize/ 1KB} ,
  20. #                       "peak KB",  {$_.peakworkingset /1KB} ) -first 2

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me