my code stock.com

Benjamin Zuel

Powershell: Visual Studio Start/Stop Debuggers
by Benjamin Zuel

PowershellModul: (.psm)
startet oder beendet die Debugger von allen derzeit geƶffneten Visual Studios

Snippet options

Download: Download snippet as powershell-visual-studio-startstop-debuggers.bat.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

Set-StrictMode -version 2

if(!$(Test-Path variable:global:vsauto_module)) {
    $Global:vsauto_module = @{ 
        # tooling - version
        Version = [version]"1.0.0";
        # The directory of the package
        PackageDirectory = "";
        # The directory of the current solution
        SolutionDirectory = "";
        # The directory of the templates
        TemplateDirectory = "";
    }
}

# make sure we stop on exceptions
$ErrorActionPreference = "Stop";

<# 
 .Synopsis
  Displays the version of the vsauto tooling.
 
 .Description
  Displays the version of the vsauto tooling.
 
 .Example
  # Display the version of the vsauto tooling.
  Get-vsautoVersion
#>
function Get-VSAutoVersion {
    return $Global:vsauto_module.Version;
}
export-modulemember -function Get-VSAutoVersion;

function Get-SolutionName {
	param ( [Parameter(Mandatory=$true, Position = 0)]$vs 
	)
	Process {
		if($vs -eq $null){
			return "null";
		}
		
		if($vs.PSObject.Properties.Match('Solution').Count) {
			$sln = $vs.Solution;
            if($sln.PSObject.Properties.Match('FileName').Count -and $sln.FileName -ne "") {
				$fn = $sln.FileName;
				if($fn -match "`.sln"){
					return [System.IO.Path]::GetFileNameWithoutExtension($fn);
				} else {
					return $fn;
				}
			} elseif($sln.PSObject.Properties.Match('FullName').Count -and $($($sln | select -ExpandProperty 'FullName') -ne "")) {
				$fn = $($sln | select -ExpandProperty 'FullName');
				if($fn -cmatch "`.sln"){
					return [System.IO.Path]::GetFileNameWithoutExtension($fn);
				} else {
					return $fn;
				}
			} elseif($sln.PSObject.Properties.Match('Name').Count -and $sln.Name -ne ""){
				return $sln.Name;
			}
		} else {
			return "No name";
		}
	}
}

function Stop-Debuggers {
	param ( 
		[Parameter(Mandatory=$false, Position = 0)]
		[switch]$All,
		[Parameter(Mandatory=$false, Position = 1)]
		[string]$SolutionName 
	)
	
	Process {
		$dtes = $(Get-Process | ?{ $_.ProcessName -eq 'devenv' } | Get-DTE);
        $obj = $($dtes | %{ New-Object PSObject @{ SolutionName = $(Get-SolutionName $_); DTE = $_ } });

		if($All -eq $true -and ($SolutionName -eq $null -or $SolutionName -eq "")){
            $obj | %{ $_.DTE.Debugger.TerminateAll() | Out-Null; } | Out-Null;
		} elseif($All -eq $false -and ($SolutionName -ne $null -and $SolutionName -ne "")) {
            $obj = $($obj | ?{ $_.SolutionName -eq $SolutionName });
			$obj | %{ $_.DTE.Debugger.TerminateAll() | Out-Null; } | Out-Null;
		}

        $obj | %{ Write-Host $($_.SolutionName + " Debugger stopped") };
	}
}
export-modulemember -function Stop-Debuggers;

function Start-Debuggers {
	param ( 
		[Parameter(Mandatory=$false, Position = 0)]
		[switch]$All,
		[Parameter(Mandatory=$false, Position = 1)]
		[string]$SolutionName 
	)
	
	Process {
        $dtes = $(Get-Process | ?{ $_.ProcessName -eq 'devenv' } | Get-DTE);
        $obj = $($dtes | %{ New-Object PSObject @{ SolutionName = $(Get-SolutionName $_); DTE = $_ } } | ?{ $_.DTE.Debugger.CurrentMode -ne 3 });

		if($All -eq $true -and ($SolutionName -eq $null -or $SolutionName -eq "")){
            $obj | %{ $_.DTE.Debugger.Go($false) | Out-Null; } | Out-Null;
		} elseif($All -eq $false -and ($SolutionName -ne $null -and $SolutionName -ne "")) {
            $obj = $($obj | ?{ $_.SolutionName -eq $SolutionName });
			$obj | %{ $_.DTE.Debugger.Go($false) | Out-Null; } | Out-Null;
		}

        $obj | %{ Write-Host $($_.SolutionName + " Debugger started") };
	}
}
export-modulemember -function Start-Debuggers;


Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.