Skip to content

Instantly share code, notes, and snippets.

Avatar
⚙️
Automating things.......from home!

Luke Leigh BanterBoy

⚙️
Automating things.......from home!
View GitHub Profile
View Microsoft.PowerShell_profile.ps1
# 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 Jan 3, 2021
On-Premise Exchange Connection Functions
View OnPremExchangeSession.ps1
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 Aug 23, 2020
docker-compose.yml file for Jekyll Pages Blog Server
View docker-compose.yml
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 Sep 11, 2020
I have added these functions to my Profile in order to speed up the blogging process
View Start-Blogging.ps1
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 Aug 14, 2020
This will display the user account and whether the session is running as admin in the WindowTitle
View DisplayAdmin-WindowTitle.ps1
# 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 Aug 14, 2020
Function used in conjunction with Test-IsAdmin display warning message when opening profile/script
View Show-IsAdminOrNot.ps1
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 Aug 14, 2020
Function used in conjunction with Test-IsAdmin to start a new Microsoft Terminal as Admin
View New-AdminTerminal.ps1
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 Aug 14, 2020
Function used in conjunction with Test-IsAdmin to start a new Admin Shell (runs powershell or pwsh as admin)
View New-AdminShell.ps1
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 Aug 14, 2020
Function to test if the current session is running as an administrator
View Test-IsAdmin.ps1
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 Aug 10, 2020
Powershell cmdlet for locating recent files in a specified folder.
View Get-LatestFiles.ps1
<#
.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