Skip to content

Instantly share code, notes, and snippets.

View BanterBoy's full-sized avatar
⚙️
Automating things.......from home!

Luke Leigh BanterBoy

⚙️
Automating things.......from home!
View GitHub Profile
@BanterBoy
BanterBoy / Microsoft.PowerShell_profile.ps1
Last active January 21, 2024 15:31
Example PowerShell Profile
# Add required assemblies
Add-Type -AssemblyName WindowsBase
Add-Type -AssemblyName PresentationCore
# Pause to be able to press and hold a key
Start-Sleep -Seconds 1
# Key list
$Nokey = [System.Windows.Input.Key]::None
$key1 = [System.Windows.Input.Key]::LeftCtrl
@BanterBoy
BanterBoy / OnPremExchangeSession.ps1
Created January 3, 2021 05:53
On-Premise Exchange Connection Functions
function New-OnPremExchangeSession {
param (
[Parameter(ValueFromPipeline = $True,
HelpMessage = "Enter preferred Exchange Server")]
[ValidateSet('MAIL01', 'MAIL02') ]
[string[]]$ComputerName
)
switch ($ComputerName) {
MAIL01 {
$Creds = Get-Credential
@BanterBoy
BanterBoy / docker-compose.yml
Created August 23, 2020 01:37
docker-compose.yml file for Jekyll Pages Blog Server
jekyll:
image: jekyll/jekyll:pages
command: jekyll serve --watch --incremental --force_polling
ports:
- 4000:4000
container_name: blog_server
volumes:
- ".:/srv/jekyll"
- "./vendor/bundle:/usr/local/bundle"
@BanterBoy
BanterBoy / Start-Blogging.ps1
Last active September 11, 2020 00:26
I have added these functions to my Profile in order to speed up the blogging process
function Test-IsAdmin {
<#
.Synopsis
Tests if the user is an administrator
.Description
Returns true if a user is an administrator, false if the user is not an administrator
.Example
Test-IsAdmin
#>
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
@BanterBoy
BanterBoy / DisplayAdmin-WindowTitle.ps1
Created August 14, 2020 19:22
This will display the user account and whether the session is running as admin in the WindowTitle
# Display running as Administrator in WindowTitle
$whoami = whoami /Groups /FO CSV | ConvertFrom-Csv -Delimiter ','
$MSAccount = $whoami."Group Name" | Where-Object { $_ -like 'MicrosoftAccount*' }
$LocalAccount = $whoami."Group Name" | Where-Object { $_ -like 'Local' }
#$MSAccount.Split('\')[1]
#$env:USERNAME
if ((Test-IsAdmin) -eq $true) {
@BanterBoy
BanterBoy / Show-IsAdminOrNot.ps1
Created August 14, 2020 19:18
Function used in conjunction with Test-IsAdmin display warning message when opening profile/script
function Show-IsAdminOrNot {
$IsAdmin = Test-IsAdmin
if ( $IsAdmin -eq "False") {
Write-Warning -Message "Admin Privileges!"
}
else {
Write-Warning -Message "User Privileges"
}
}
@BanterBoy
BanterBoy / New-AdminTerminal.ps1
Created August 14, 2020 19:15
Function used in conjunction with Test-IsAdmin to start a new Microsoft Terminal as Admin
function New-AdminTerminal {
<#
.Synopsis
Starts an Elevated Microsoft Terminal.
.Description
Opens a new Microsoft Terminal Elevated as Administrator. If the user is already running an elevated
Microsoft Terminal, a message is displayed in the console session.
.Example
@BanterBoy
BanterBoy / New-AdminShell.ps1
Created August 14, 2020 19:13
Function used in conjunction with Test-IsAdmin to start a new Admin Shell (runs powershell or pwsh as admin)
function New-AdminShell {
<#
.Synopsis
Starts an Elevated PowerShell Console.
.Description
Opens a new PowerShell Console Elevated as Administrator. If the user is already running an elevated
administrator shell, a message is displayed in the console session.
.Example
@BanterBoy
BanterBoy / Test-IsAdmin.ps1
Created August 14, 2020 19:11
Function to test if the current session is running as an administrator
function Test-IsAdmin {
<#
.Synopsis
Tests if the user is an administrator
.Description
Returns true if a user is an administrator, false if the user is not an administrator
.Example
Test-IsAdmin
#>
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
@BanterBoy
BanterBoy / Get-LatestFiles.ps1
Created August 10, 2020 19:28
Powershell cmdlet for locating recent files in a specified folder.
<#
.SYNOPSIS
Short function to find recently saved files.
.DESCRIPTION
Short function that can be used to find/locate recently saved files.
Searches are performed by passing the parameters to Get-Childitem which will then
recursively search through your specified file path and then perform a sort to output