Guest User

Untitled

a guest
Dec 11th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. function InvokePowerShellCommand
  2. {
  3. [CmdletBinding()]
  4. param
  5. (
  6. [Parameter()]
  7. [ValidateNotNullOrEmpty()]
  8. [string]$Command
  9. )
  10.  
  11. $Command | powershell.exe -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -Command -
  12. }
  13.  
  14. function ConvertTo-String
  15. {
  16. [OutputType([string])]
  17. [CmdletBinding()]
  18. param
  19. (
  20. [Parameter(Mandatory)]
  21. [ValidateNotNullOrEmpty()]
  22. [hashtable]$Hashtable
  23. )
  24. $arr = $Hashtable.GetEnumerator().foreach({
  25. if ($_.Value -is 'hashtable') {
  26. "'$($_.Key)' = $(ConvertTo-String -HashTable $_.Value)"
  27. } else {
  28. "'$($_.Key)' = '$($_.Value)'"
  29. }
  30. })
  31. '@{{ {0} }}' -f ($arr -join ';')
  32. }
  33.  
  34. function ConvertHashTableParametersToString
  35. {
  36. [OutputType([string])]
  37. [CmdletBinding()]
  38. param
  39. (
  40. [Parameter()]
  41. [ValidateNotNullOrEmpty()]
  42. [hashtable]$Parameters
  43. )
  44. $Parameters.GetEnumerator().foreach({
  45. $paramName = $_.Key
  46.  
  47. if ($_.Value -is [System.Management.Automation.SwitchParameter]) {
  48. if ($_.Value) {
  49. '-{0}' -f $paramName
  50. }
  51. }
  52. else {
  53. if ($_.Value -is 'hashtable') {
  54. $paramValue = ConvertTo-String -HashTable $_.Value
  55. }
  56. else {
  57. $paramValue = '"{0}"' -f (@($_.Value) -join '","')
  58. }
  59.  
  60. '-{0} {1}' -f $paramName,$paramValue
  61. }
  62. })
  63. }
  64.  
  65. function Start-Pester
  66. {
  67. [CmdletBinding()]
  68. param(
  69. [Parameter()]
  70. [ValidateNotNullOrEmpty()]
  71. [string]$Path,
  72. [switch]$PassThru,
  73. [switch]$Quiet
  74. )
  75.  
  76. $invPesterParams = @{
  77. Path = $Path
  78. Show = if (-not $Quiet) { "All" } else { 'Fails' }
  79. PassThru = $PassThru
  80. }
  81.  
  82. ## Can't splat here because we're passing to another powershell.exe process
  83. $invPesterParamString = ConvertHashTableParametersToString -Parameters $invPesterParams
  84.  
  85. $command = "Invoke-Pester $invPesterParamString "
  86. if (-not $PassThru) {
  87. InvokePowerShellCommand -Command $command
  88. }
  89. else {
  90. $log = New-TemporaryFile
  91. try {
  92. $output = InvokePowerShellCommand -Command ($command + " | Export-CliXml -Encoding utf8 $($log.FullName)")
  93.  
  94. Import-CliXml $log
  95. }
  96. finally {
  97. Remove-Item $log
  98. }
  99. }
  100. }
Add Comment
Please, Sign In to add comment