Some Powershell Scripts

By popular demand, I uploaded a bunch of my scripts to my SkyDrive. Included are:

  • Set Powershell Home – this is actually a zip file that contains the profile redirect script. Unzip this in your Documents folder and change the path in Microsoft.PowerShell_profile to where ever you want your profile and home directories to live.
  • _profile – my “real” profile script. Note, the su function requires the Script Elevation PowerToys in order to work. Also, all the various aliases are hard coded to their location on my machine. You’ll probably want to change them.
  • prompt – my prompt script
  • prepend-path – a script to add a directory to start of my path
  • append-path – like above, but adds the directory to the end of the path
  • append-path-perm – like append-path, but permanently updates the path in the registry

Enjoy.

Comments:

From profile.ps1: > cmd.exe /c color 4f You can control the colours that PSH's console host uses by assigning to the members of $Host.PrivateData. E.g. $Host.PrivateData.WarningForegroundColor = "green" (Each is of type [System]::ConsoleColor)
@Richard, Thanks. However, that doesn't appear to let me set the background for the command shell window as a whole though. Only, the Warning, Error, Debug, Verbose and Progress fore & background colors. I can see the value of that, but my goal with that line of script is to set the entire background to red.
If you want to change the settings for the console, use $host.ui.rawui.foregroundcolor and .background color. I have functions like this: function green { $host.ui.rawui.foregroundcolor = "Green"; $host.ui.rawui.backgroundcolor = "Black" } function yellow { $host.ui.rawui.foregroundcolor = "Yellow"; $host.ui.rawui.backgroundcolor = "Black" }
> However, that doesn't appear to let me set the background for the command shell window as a whole though Follow it with a Clear-Host My current^h finally implemented elevated PSH (use scope modifiers so don't just create a local variable in the condition block containing this): $host.UI.RawUI.Backgroundcolor="DarkGray" $host.UI.RawUI.Foregroundcolor="Red" clear-host write-host "`n** Elevated Session **`n" -foreground DarkRed -background Yellow $global:ConsolePromptColour = "Red" # Override prompt function's default $global:ConfirmPreference = "Medium"
Thanks Tommy and Richard! I updated my _profile script to use instead of $host.UI.RawUI.Backgroundcolor cmd.exe /c color.