-
-
Save pezhore/7b3105ef4a82b1b0e3ba to your computer and use it in GitHub Desktop.
Microsoft.PowerShell_profile.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# BMAR's PS profile | |
# last updated 9/26/2013 | |
$a = (Get-Host).UI.RawUI | |
$a.backgroundcolor = "Black" | |
clear | |
############################################# | |
# BEGIN PS Snapins # | |
############################################# | |
if (!($env:PSModulePath -match "git-code")){ | |
$env:PSModulePath = $env:PSModulePath + ";C:\scripting\git-code\powershell\modules" | |
} | |
$questPresent = $powerclipresent = $true | |
try { | |
add-PSSnapin quest.activeroles.admanagement -ErrorAction Stop | |
} catch { | |
Write-host "Quest Active roles not installed" | |
$questpresent = $false | |
} | |
try { | |
add-pssnapin VMware.DeployAutomation -ErrorAction Stop | |
add-pssnapin VMware.ImageBuilder -ErrorAction Stop | |
add-pssnapin VMware.VimAutomation.Cloud -ErrorAction Stop | |
add-pssnapin VMware.VimAutomation.Core -ErrorAction Stop | |
add-pssnapin VMware.VimAutomation.License -ErrorAction Stop | |
add-pssnapin VMware.VimAutomation.Vds -ErrorAction Stop | |
} catch { | |
write-host "VMware PowerCLI not installed" | |
$powerclipresent = $false | |
} | |
try { | |
import-module Posh-Git -ErrorAction Stop | |
} catch { | |
write-host "Posh-Git Module not found. Please check PSModule Path" | |
} | |
try { | |
import-module admintools -ErrorAction Stop | |
} catch { | |
write-host "Admintools Module not found. Please check PSModule Path" | |
} | |
############################################# | |
# END PS Snapins # | |
############################################# | |
############################################# | |
# BEGIN Variables # | |
############################################# | |
$ping = New-Object System.Net.Networkinformation.ping | |
if ($powerclipresent){ | |
$psMajor = (get-powercliversion).major | |
$psMinor = (get-powercliversion).minor | |
} | |
############################################# | |
# END Variables # | |
############################################# | |
[void][Reflection.Assembly]::LoadWithPartialName("VMware.Vim") | |
############################################# | |
# BEGIN Aliases # | |
############################################# | |
New-Alias sign Set-AuthenticodeSignature | |
New-Alias which get-command | |
New-Alias pop pop-location | |
New-Alias push push-location | |
if ((test-path "c:\Program Files (x86)\Vim\vim73\vim.exe")){ | |
New-Alias vi "c:\Program Files (x86)\Vim\vim73\vim.exe" | |
} | |
if ((test-path "c:\Program Files\Vim\vim73\vim.exe")){ | |
New-Alias vi "c:\Program Files\Vim\vim73\vim.exe" | |
} | |
New-Alias -name sudo 'c:\scripting\git-code\powershell\ps_misc\sudo.ps1' | |
Set-Alias Answer-VMQuestion Set-VMQuestion | |
############################################# | |
# END Aliases # | |
############################################# | |
############################################# | |
# BEGIN Functions # | |
############################################# | |
function whoami { (get-content env:\userdomain) + "\" + (get-content env:\username); } | |
# open documentation file | |
function Get-PowerCLIHelp{ | |
$regKeys = Get-ItemProperty "hklm:\software\VMware, Inc.\VMware VI Toolkit (for Windows)" -ErrorAction SilentlyContinue | |
#64bit os fix | |
if($regKeys -eq $null){ | |
$regKeys = Get-ItemProperty "hklm:\software\wow6432node\VMware, Inc.\VMware VI Toolkit (for Windows)" -ErrorAction SilentlyContinue | |
} | |
$ChmFilePath = $regKeys.InstallPath + "$productName Cmdlets Reference.chm" | |
$docProcess = [System.Diagnostics.Process]::Start($ChmFilePath) | |
} | |
function Get-VICommand() { get-command -pssnapin VMware.VimAutomation.Core } | |
function Get-QCommand() { get-command -pssnapin Quest.ActiveRoles* } | |
function preparehost{ | |
$ui = (get-host).UI.RawUI | |
$ui.ForegroundColor = 'gray' | |
} | |
function prompt{ | |
#change title bar text | |
$title = "[$productName] Not Connected" | |
if(($DefaultVIServer -ne $null) -and ($DefaultVIServer.IsConnected) ){ | |
$title = "[$productName] Connected to " + $DefaultVIServer.Name + " as " + $DefaultVIServer.User | |
} | |
$host.ui.rawui.WindowTitle = $title | |
# change prompt text | |
Write-Host "[" -NoNewLine | |
Write-Host "$productName" -NoNewLine -foregroundcolor green | |
Write-Host "] " -NoNewLine | |
Write-Host ((Get-location).Path + ">") -NoNewLine | |
return " " | |
} | |
function get-banner | |
{ | |
write-host -fore Green "`n Welcome $([Environment]::UserName). Would you like to play a game?`n" | |
if ($questpresent){ | |
write-host -fore Cyan "`n Quest Active Directory Plugins... activated`n" | |
write-host -fore Gray "List only Management Shell cmdlets: " -no | |
write-host -fore Yellow "Get-QCommand" | |
write-host -fore Gray "Get connected to the domain: " -no | |
write-host -fore Yellow "connect-QADService`n" | |
} | |
if ($powerclipresent){ | |
write-host -fore Cyan "`n PowerCLI $psmajor.$psminor Plugins................. activated`n" | |
write-host -fore Gray "List only PowerCLI cmdlets: " -no | |
write-host -fore yellow "Get-VICommand" | |
write-host -fore Gray "Log in to a vCenter Server or ESX host: " -no | |
write-host -fore yellow "Connect-VIServer" | |
write-host -fore Gray "To show searchable help for all PowerCLI commands: " -no | |
write-host -fore yellow "Get-PowerCLIHelp" | |
} | |
write-host "`n`n" | |
} | |
######################################################## | |
# 'go' command and targets | |
if( $GLOBAL:go_locations -eq $null ) { | |
$GLOBAL:go_locations = @{}; | |
} | |
function go ([string] $location) { | |
if( $go_locations.ContainsKey($location) ) { | |
set-location $go_locations[$location]; | |
} else { | |
write-output "The following locations are defined:"; | |
write-output $go_locations; | |
} | |
} | |
$go_locations.Add("home", "~") | |
if (test-path $($env:USERPROFILE+"\Downloads")){ | |
$go_locations.Add("dl", $env:USERPROFILE+"\Downloads") | |
} | |
if (test-path "c:\scripting\git-code\powershell") { | |
$go_locations.Add("scripts", "c:\scripting\git-code\powershell") | |
} | |
if (test-path $($env:USERPROFILE+"\Documents\My Box Files")) { | |
$go_locations.Add("box", $env:USERPROFILE+"\Documents\My Box Files") | |
} | |
$profilePath = ([System.IO.FileInfo] $profile).DirectoryName | |
$go_locations.Add("profile", $profilePath) | |
######################################################## | |
function prep-PSScriptComments{ | |
param($file) | |
BEGIN { | |
$content = Get-Content $file | |
$psPrep = "<#`n`t.SYNOPSIS`n`t`n`t.DESCRIPTION`n`t`n`t.EXAMPLE`n`t`n`t.PARAMETER`n`t`n`t.NOTES`n`t`Author: Brian Marsh`n`tVersion: 1.0`n#>`n" | |
} | |
PROCESS { | |
$psPrep | Set-Content $file | |
} | |
END { | |
$content | Add-Content $file | |
} | |
} | |
preparehost | |
get-banner | |
$powerclipresent = $questpresent = $null | |
go scripts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment