Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function InvokePowerShellCommand
- {
- [CmdletBinding()]
- param
- (
- [Parameter()]
- [ValidateNotNullOrEmpty()]
- [string]$Command
- )
- $Command | powershell.exe -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -Command -
- }
- function ConvertTo-String
- {
- [OutputType([string])]
- [CmdletBinding()]
- param
- (
- [Parameter(Mandatory)]
- [ValidateNotNullOrEmpty()]
- [hashtable]$Hashtable
- )
- $arr = $Hashtable.GetEnumerator().foreach({
- if ($_.Value -is 'hashtable') {
- "'$($_.Key)' = $(ConvertTo-String -HashTable $_.Value)"
- } else {
- "'$($_.Key)' = '$($_.Value)'"
- }
- })
- '@{{ {0} }}' -f ($arr -join ';')
- }
- function ConvertHashTableParametersToString
- {
- [OutputType([string])]
- [CmdletBinding()]
- param
- (
- [Parameter()]
- [ValidateNotNullOrEmpty()]
- [hashtable]$Parameters
- )
- $Parameters.GetEnumerator().foreach({
- $paramName = $_.Key
- if ($_.Value -is [System.Management.Automation.SwitchParameter]) {
- if ($_.Value) {
- '-{0}' -f $paramName
- }
- }
- else {
- if ($_.Value -is 'hashtable') {
- $paramValue = ConvertTo-String -HashTable $_.Value
- }
- else {
- $paramValue = '"{0}"' -f (@($_.Value) -join '","')
- }
- '-{0} {1}' -f $paramName,$paramValue
- }
- })
- }
- function Start-Pester
- {
- [CmdletBinding()]
- param(
- [Parameter()]
- [ValidateNotNullOrEmpty()]
- [string]$Path,
- [switch]$PassThru,
- [switch]$Quiet
- )
- $invPesterParams = @{
- Path = $Path
- Show = if (-not $Quiet) { "All" } else { 'Fails' }
- PassThru = $PassThru
- }
- ## Can't splat here because we're passing to another powershell.exe process
- $invPesterParamString = ConvertHashTableParametersToString -Parameters $invPesterParams
- $command = "Invoke-Pester $invPesterParamString "
- if (-not $PassThru) {
- InvokePowerShellCommand -Command $command
- }
- else {
- $log = New-TemporaryFile
- try {
- $output = InvokePowerShellCommand -Command ($command + " | Export-CliXml -Encoding utf8 $($log.FullName)")
- Import-CliXml $log
- }
- finally {
- Remove-Item $log
- }
- }
- }
Add Comment
Please, Sign In to add comment