WindowsPowerShell

From HasnoWiki

Jump to: navigation, search

PowerShell config

Put profile.ps1 in %userprofile%\Documents\WindowsPowerShell

Powershell.png

Profile.ps1

$global:CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$global:Admin = "%" 
$principal = New-Object System.Security.Principal.WindowsPrincipal($CurrentUser)
if ($principal.IsInRole("Administrators"))
{
    $Admin = "#"
}
 
function prompt
{ 
  $oldpos = $host.UI.RawUI.CursorPosition
  $eol = $oldpos
  $currentDir = get-location
  $histCnt = (Get-History -Count 1).Id + 1 
  $dirlen = $currentDir.ToString().Length
  $eol.X = ($host.UI.RawUI.WindowSize.Width-$dirlen)-2 
  $hostinfo = $env:Username + "@" + $env:Userdomain.ToLower()
  $host.UI.RawUI.WindowTitle = "(" + $hostinfo + ") " + $(get-location) 
  $host.UI.RawUI.CursorPosition = $eol
  Write-Host -NoNewLine -ForeGroundColor DarkGray "(";
  Write-Host -NoNewLine -ForeGroundColor White $currentDir;
  Write-Host -NoNewLine -ForeGroundColor DarkGray ")";
  $host.UI.RawUI.CursorPosition = $oldpos 
  Write-Host -NoNewLine -ForeGroundColor DarkGray "(";
  Write-Host -NoNewline -ForeGroundColor DarkCyan $env:Username; 
  Write-Host -NoNewline -ForeGroundColor Cyan "@"; 
  Write-Host -NoNewline -ForeGroundColor DarkCyan $env:Userdomain.ToLower(); 
  Write-Host -NoNewLine -ForeGroundColor DarkGray ")";
  Write-Host -NoNewLine -ForeGroundColor DarkGray "(";
  Write-Host -NoNewLine -ForeGroundColor Cyan $histCnt;
  Write-Host -NoNewLine -ForeGroundColor DarkGray ")"; $Admin + " ";    
  return ""
}   
function out-default {
    end {
        $input | &(Get-Command -Type Cmdlet Out-Default)
        $host.UI.RawUI.ForegroundColor = "Gray";
    }
} 
. ($home + "\My Documents\WindowsPowerShell\TabExpansion.ps1")

PowerShellHere.Inf

;
; "PowerShell Here" PowerToy
;
; Copyright 2006 Scott Hanselman
; http://www.computerzen.com
;
; Modified by Mark Guzman, 2006
;
; Modified using the VS2003 Command Shell Here tool as a template May 4, 2006
;

[version]
signature="$CHICAGO$"

[PowerShellHereInstall]
CopyFiles = PowerShellHere.Files.Inf
AddReg    = PowerShellHere.Reg

[DefaultInstall]
CopyFiles = PowerShellHere.Files.Inf
AddReg    = PowerShellHere.Reg

[DefaultUnInstall]
DelFiles  = PowerShellHere.Files.Inf
DelReg    = PowerShellHere.Reg

[SourceDisksNames]
55="Open PowerShell Prompt Here","",1 
[SourceDisksFiles]
PowerShellHere.INF=55

[DestinationDirs]
PowerShellHere.Files.Inf = 17 

[PowerShellHere.Files.Inf]
PowerShellHere.INF 

[PowerShellHere.Reg]
HKLM,%UDHERE%,DisplayName,,"%PowerShellHereName%"
HKLM,%UDHERE%,UninstallString,,"rundll32.exe syssetup.dll,SetupInfObjectInstallAction DefaultUninstall 132 %17%\PowerShellHere.inf"
HKCR,Directory\Shell\PowerShellHere,,,"%PowerShellHereAccel%"
HKCR,Directory\Shell\PowerShellHere\command,,,"""c:\windows\system32\windowspowershell\v1.0\powershell.exe"" -NoExit -Command ""cd '%1'"""
HKCR,Drive\Shell\PowerShellHere,,,"%PowerShellHereAccel%"
HKCR,Drive\Shell\PowerShellHere\command,,,"""c:\windows\system32\windowspowershell\v1.0\powershell.exe"" -NoExit -Command ""cd '%1'""" 
[Strings]
PowerShellHereName="PowerShell Prompt Here PowerToy"
PowerShellHereAccel="&PowerShell Prompt Here"
UDHERE="Software\Microsoft\Windows\CurrentVersion\Uninstall\PowerShellHere"