1: #### Functions Used to Load VS Command Prompt #####
2:
3: function Get-Batchfile ($file) {
4: $cmd = "`"$file`" & set"
5: cmd /c $cmd | Foreach-Object {
6: $p, $v = $_.split('=')
7: Set-Item -path env:$p -value $v
8: }
9: }
10:
11: function VsVars32()
12: {
13: $version = "9.0"
14: $key = "HKLM:SOFTWARE\Microsoft\VisualStudio\" + $version
15: $VsKey = Get-ItemProperty $key
16: $VsInstallPath = [System.IO.Path]::GetDirectoryName($VsKey.InstallDir)
17: $VsToolsDir = [System.IO.Path]::GetDirectoryName($VsInstallPath)
18: $VsToolsDir = [System.IO.Path]::Combine($VsToolsDir, "Tools")
19: $vs90comntools = (Get-ChildItem env:VS90COMNTOOLS).Value
20: $batchFile = [System.IO.Path]::Combine($vs90comntools, "vsvars32.bat")
21: Get-Batchfile $batchFile
22: [System.Console]::Title = "Visual Studio " + $version + " Windows Powershell"
23: }
24:
25: ###### Functions Used to Load VS Command Prompt #####
26:
27: ###### Function Used to Set Background to Light Blue If not Admin ######
28:
29: function AmIAdmin()
30: {
31: $wid=[System.Security.Principal.WindowsIdentity]::GetCurrent()
32: $prp=new-object System.Security.Principal.WindowsPrincipal($wid)
33: $adm=[System.Security.Principal.WindowsBuiltInRole]::Administrator
34: $IsAdmin=$prp.IsInRole($adm)
35: $title = [System.Console]::Title
36: if (!$IsAdmin)
37: {
38: $title = $title + " (Non-Administrator)"
39: (Get-Host).UI.RawUI.Backgroundcolor="Blue"
40: cls
41: }
42: else
43: {
44: $title = $title + " (Administrator)"
45: }
46: [System.Console]::Title = $title
47: }
48:
49:
50: ###### Run Functions on StartuP ######
51: VsVars32
52: AmIAdmin