Guest User

Untitled

a guest
May 22nd, 2012
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. Powershell hashtables as argument to custom cmdlet in C#
  2. import-module .MyClassLib.dll
  3.  
  4. $task = New-Object MyClassLib.OracleScript -Property @{
  5. Files="MyScript.sql"
  6. Database="TEST"
  7. User="USER"
  8. Password="PASSWORD"
  9. }
  10. $result = $task.Execute()
  11.  
  12. Invoke-OracleScript @{
  13. Files="Script.sql"
  14. Database="db"
  15. User="user"
  16. Password="password"
  17. }
  18.  
  19. Invoke-OracleScript @{
  20. Files="Script.sql";
  21. Database="db";
  22. User="user";
  23. Password="password";
  24. }
  25.  
  26. Invoke-OracleScript -Property @{
  27. Files="Script.sql"
  28. Database="db"
  29. User="user"
  30. Password="password"
  31. }
  32.  
  33. [Cmdlet(VerbsLifecycle.Invoke, "OracleScript", ConfirmImpact = ConfirmImpact.High, SupportsShouldProcess = true, SupportsTransactions = false)]
  34. public class Invoke_OracleScript : Cmdlet, IOracleScript
  35. {
  36. [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
  37. public string Files { get; set; }
  38.  
  39. [Parameter(Mandatory = true, Position = 1, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
  40. public string Database { get; set; }
  41. ....
  42.  
  43. get-process -Name notepad `
  44. -Computername localhost `
  45. -Verbose
  46.  
  47. $process = new-object psobject
  48. $process | add-member -name name -value notepad -type noteproperty
  49. $process | add-member -name computername -value localhost -type noteproperty
  50. $process | get-process
  51.  
  52. $process = new-object psobject -property @{ name="notepad";
  53. computername = "localhost";}
  54.  
  55. $process | get-process
  56.  
  57. Function Add-ThreeNumbers {
  58. param ($a,$b,$c)
  59. $a + $b + $c
  60. }
  61.  
  62. $params = @{a=10; b=15; c = 20}
  63.  
  64. Add-ThreeNumbers @params
Advertisement
Add Comment
Please, Sign In to add comment