Skip to content

Instantly share code, notes, and snippets.

@MartiUK
Created April 25, 2014 12:59
Show Gist options
  • Save MartiUK/11288776 to your computer and use it in GitHub Desktop.
Save MartiUK/11288776 to your computer and use it in GitHub Desktop.
# Initialise
$env:Path = $env:Path + ";C:\Users\mkemp\Documents\WindowsPowerShell"
$ScriptFolder = "C:\Users\mkemp\Documents\WindowsPowerShell\"
# Initialise aliases
Set-Alias subl 'C:\Users\mkemp\Desktop\sublimetext\sublime_text.exe'
function prompt {
# our theme
$cdelim = [consolecolor]::DarkCyan
$chost = [consolecolor]::Green
$cloc = [consolecolor]::Cyan
$cadm = [consolecolor]::Red
$lamb = [consolecolor]::Gray
Write-Host "$([char]0x3bb) " -n -f $lamb
Write-Host ([net.dns]::GetHostName()) -n -f $chost
Write-Host ' {' -n -f $cdelim
Write-Host (shorten-path (pwd).Path) -n -f $cloc
Write-Host '}' -n -f $cdelim
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole]"Administrator"))
{
Write-Host '$' -n -f $chost
} else {
Write-Host '#' -n -f $cadm
}
return ' '
}
#create a function to handle choices for transcripts or not
function set-record {
$on = Read-Host "Do you wish to record this session? [yes or no]"
if ($on -eq "yes")
{
Start-Transcript
}
else
{
Write-Host "This session is not being recorded"
}
}
#prompt for recording
set-record
#create function to kill processes on specified machine
function manage-process {
param(
[Parameter(Mandatory = $false,Position = 0)] [string]$pc,
[Parameter(Mandatory = $true,Position = 1)] [string]$proc,
[Parameter(Mandatory = $true,Position = 2)] [string]$action
)
$proclist = Get-Process $proc -ComputerName $pc
if ($action -eq "stop")
{
$proclist | Stop-Process
Write-Host "Process " $proclist.ProcessName " stopped on " $pc
}
else
{
$proclist
}
}
function ms {
param(
[Parameter(Mandatory = $false,Position = 0)] [string]$pc,
[Parameter(Mandatory = $true,Position = 1)] [string]$serv,
[Parameter(Mandatory = $true,Position = 2)] [string]$action)
}
function check-serverservices {
Get-Service -ComputerName PMALPHABATCH1 | Where-Object {$_.displayname -like 'ZULU*'}
Get-Service -ComputerName PMALPHABATCH2 | Where-Object {$_.displayname -like 'ZULU*'}
}
function remove-extension {
param([Parameter()] [validatenotnullorempty][string]$ext = $(throw "The extension is required example"))
if ($ext -eq $null) {
gci *.0000* | % { ren $_.fullname -NewName $_.basename -Verbose }
}
else {
gci $ext | % { ren $_.fullname -NewName $_.basename -Verbose }
}
}
function list-scripts {
Get-ChildItem $ScriptFolder -Name -Include '*.ps1' -Exclude 'Microsoft.PowerShell_profile.ps1'
}
function get-shares {
param([Parameter()] [string]$computer = $(throw "The computer name is required"))
Get-WmiObject -Class Win32_Share -ComputerName $computer
}
function shorten-path ([string]$path) {
$loc = $path.Replace($HOME,'~')
# remove prefix for UNC paths
$loc = $loc -replace '^[^:]+::',''
# make path shorter like tabs in Vim,
# handle paths starting with \\ and . correctly
return ($loc -replace '\\(\.?)([^\\])[^\\]*(?=\\)','\$1$2')
}
function show-off {
$cadm = [consolecolor]::DarkGreen
Write-Host "
___ _
\ \ ___ _ __ ___ __| | ___ _ __
/ \ / __| '_ `` _ \ / _`` |/ _ \ '__|
/ /\ \| (__| | | | | | (_| | __/ |
/_/ \_\\___|_| |_| |_|\__,_|\___|_|
-- 1.1.4 $([net.dns]::GetHostName()) https://github.com/bliker/cmder"-f $cadm
}
show-off
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment