⬆️ ⬇️

Visual Studio 2008 PowerShell Command Prompt

I like PowerShell, it is more functional and more readable than cmd. But bad luck - sometimes you have to open the command line of Visual Studio, but it is not PowerShell. I want to execute ls and nmake from the same console.



Alternatively, it would be possible to take vsvars32.bat and rewrite it, but this is a frank outrage on free time and there is an easier way -

blogs.msdn.com/domgreen/archive/2009/05/03/visual-studio-command-prompt-via-powershell.aspx . I changed the script a bit to clean up the garbage.





#

# bat

# PowerShell

#

function Get-BatchFile( $batFile ) {

$command = "`"$batFile`" & set"

cmd /c $command | Foreach-Object {

$name, $value = $_.split('=')

Set-Item -path env:$name -value $value

}

}



#

# PowerShell Visual Studio 2008 Command Prompt

#

function SetupVisualStudio2008Prompt( ) {

#

$batFile = [System.IO.Path]::Combine( $env:VS90COMNTOOLS, "vsvars32.bat" )

Get-BatchFile $batFile

$title = "Visual Studio 2008 Windows PowerShell"



#

$wid = [System.Security.Principal.WindowsIdentity]::GetCurrent( )

$principal = new-object System.Security.Principal.WindowsPrincipal($wid)

$isAdmin = $principal.IsInRole( [System.Security.Principal.WindowsBuiltInRole]::Administrator )

if( $isAdmin ) {

$title = $title + " (Administrator)"

}

else {

$title = $title + " (Non-Administrator)"

}



#

[System.Console]::Title = $title

}



#

# PowerShell

#

SetupVisualStudio2008Prompt

cls



')

When launched, PowerShell loads the profile contents from Documents / WindowsPowerShell / profile.ps1. Therefore, having written the profile.ps1 script and allowing the execution of scripts in PowerShell, we will get the PowerShell command line configured in Visual Studio =)



PS And having set TotalCommander to call PowerShell by pressing Ctrl + X comes simply bliss =)

PPS I apologize for the indentation in the code, but I don’t understand why the code tag removes them.

Source: https://habr.com/ru/post/72035/



All Articles