Skip to content

Instantly share code, notes, and snippets.

@cob999
Last active September 21, 2018 08:51
Show Gist options
  • Save cob999/88f79eaa8c9af7594d5e536f8a5ae6fb to your computer and use it in GitHub Desktop.
Save cob999/88f79eaa8c9af7594d5e536f8a5ae6fb to your computer and use it in GitHub Desktop.
A PowerShell profile
# Create profile with
# $profileExists = Test-path $profile.CurrentUserAllHosts
# if(!$profileExists) { New-item –type file –force $profile.CurrentUserAllHosts }
# code $profile.CurrentUserAllHosts
#
if($host.Name -eq 'ConsoleHost')
{
Import-Module PSReadline
Import-Module Jump.Location
}
# Add message to indicate if running as Administrator or not
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal( [Security.Principal.WindowsIdentity]::GetCurrent() )
& {
if ($currentPrincipal.IsInRole( [Security.Principal.WindowsBuiltInRole]::Administrator )) {
write-host "Warning: PowerShell is running as an Administrator.`n" -backgroundcolor yellow -foregroundcolor black
}
else {
write-host "Warning: PowerShell is not running as an Administrator, you probably will regret this.`n" -backgroundcolor red
}
}
# Allows you to run `code $hosts`
$hosts = "C:\Windows\System32\drivers\etc\hosts"
# Handy to run before shutting down
Function Stop-Applications {
(Get-Process | ? { $_.mainwindowtitle -ne "" -and $_.processname -ne "powershell" }) | foreach {$_.CloseMainWindow()}
}
Function New-Guid {
[guid]::NewGuid() | Set-Clipboard
Write-Output Check your clipboard!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment