Skip to content

Instantly share code, notes, and snippets.

@9to5IT
9to5IT / Logging_Functions.ps1
Last active March 20, 2023 00:47
PowerShell: Logging Functions
Function Log-Start{
<#
.SYNOPSIS
Creates log file
.DESCRIPTION
Creates log file with path and name that is passed. Checks if log file exists, and if it does deletes it and creates a new one.
Once created, writes initial logging data
.PARAMETER LogPath
@michaeljbailey
michaeljbailey / InstallUnifiService.ps1
Last active January 12, 2021 08:13
Automation script for installing the Ubiquiti UniFi Controller as a Windows Service. This takes care of doing tedious things like setting JAVA_HOME or including it within your PATH variable. Use at your own risk!
# Written by Mike Bantegui (Last Updated 2015-03-05)
# Use at your own caution! I take no responsibility for any damage you may cause on your system.
# Known to support: Windows Server 2012 R2
function Request-ElevatedPrompt
{
# Adapted from Benjamin Armstrong's "A self elevating PowerShell script"
# http://blogs.msdn.com/b/virtual_pc_guy/archive/2010/09/23/a-self-elevating-powershell-script.aspx
$identity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object System.Security.Principal.WindowsPrincipal($identity)
@wpsmith
wpsmith / New-ErrorRecord.ps1
Created April 16, 2015 14:16
PowerShell: Creates an custom ErrorRecord that can be used to report a terminating or non-terminating error.
<#
.Synopsis
Creates an custom ErrorRecord that can be used to report a terminating or non-terminating error.
.Description
Creates an custom ErrorRecord that can be used to report a terminating or non-terminating error.
.Parameter Exception
The Exception that will be associated with the ErrorRecord.
@rkeithhill
rkeithhill / powershell.json
Last active February 23, 2024 23:18
PowerShell snippets file for Visual Studio Code - place in your ~\AppData\Roaming\Code\User\Snippets directory
{
"Condition statement": {
"prefix": "cond",
"body": [
"$1 { $0; break }"
],
"description": "Switch condition statement"
},
"Condition single quoted string statement": {
"prefix": "condsqstr",
@lalibi
lalibi / Set-WindowState.ps1
Last active June 13, 2024 09:51 — forked from Nora-Ballard/Set-WindowState.ps1
Hide, Show, Minimize, Maximize, etc window from Powershell.
function Set-WindowState {
<#
.SYNOPSIS
Set the state of a window.
.DESCRIPTION
Set the state of a window using the `ShowWindowAsync` function from `user32.dll`.
.PARAMETER InputObject
The process object(s) to set the state of. Can be piped from `Get-Process`.
@alirobe
alirobe / reclaimWindows10.ps1
Last active July 3, 2024 09:36
This Windows 10 Setup Script turns off a bunch of unnecessary Windows 10 telemetery, bloatware, & privacy things. Not guaranteed to catch everything. Review and tweak before running. Reboot after running. Scripts for reversing are included and commented. Fork of https://github.com/Disassembler0/Win10-Initial-Setup-Script (different defaults). N.…
###
###
### UPDATE: For Win 11, I recommend using this tool in place of this script:
### https://christitus.com/windows-tool/
### https://github.com/ChrisTitusTech/winutil
### https://www.youtube.com/watch?v=6UQZ5oQg8XA
### iwr -useb https://christitus.com/win | iex
###
###
@echo off
if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)
@rem *** Disable Some Service ***
sc stop DiagTrack
sc stop diagnosticshub.standardcollector.service
sc stop dmwappushservice
sc stop WMPNetworkSvc
sc stop WSearch
@SMSAgentSoftware
SMSAgentSoftware / New-RemoteToastNotification.ps1
Created June 11, 2019 12:59
Displays a toast notification on a remote computer
$Sender = "Trevor Jones"
$Message = "Hey buddy - ready for lunch?"
$RemoteComputer = "PC001"
Function New-ToastNotification {
Param($Sender,$Message)
# Required parameters
$AudioSource = "ms-winsoundevent:Notification.Default"
$HeaderFormat = "ImageAndTitle" # Choose from "TitleOnly", "ImageOnly" or "ImageAndTitle"
@potatoqualitee
potatoqualitee / Save-KBFile.ps1
Last active July 5, 2024 11:31
Download Windows patch files / KB (patchid like KBxxxxx) and save them to disk using PowerShell
function Save-KBFile {
<#
.SYNOPSIS
Downloads patches from Microsoft
.DESCRIPTION
Downloads patches from Microsoft
.PARAMETER Name
The KB name or number. For example, KB4057119 or 4057119.
@rkeithhill
rkeithhill / settings.json
Last active November 21, 2020 22:39
Windows Terminal home profile
// This file was initially generated by Windows Terminal 0.11.1121.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",