Skip to content

Instantly share code, notes, and snippets.

@dancing-groot
dancing-groot / Invoke-ElevatedRights.ps1
Last active May 17, 2023 16:59
Add this if your script (or a portion of) needs to run with administrative privileges
function Invoke-ElevatedRights
{
[CmdletBinding()]
param()
<#
.SYNOPSIS
Relaunch the script with elevated rights if required
.DESCRIPTION
Checks if the current user is running the script 'As Administrator'
If they are not, relaunch the script in a new process with elevated rights
<#
.SYNOPSIS
A brief description of the function or script
.DESCRIPTION
A longer description
.NOTES
Version: yyyy.mm.dd
Author: Author Name
Info: Release Notes
#>
@dancing-groot
dancing-groot / Write-Event.ps1
Last active January 16, 2025 12:12
A framework for creating an event log, writing to it and optionally writing to the output if that's not possible for some reason
[CmdletBinding()]
param()
# This works for PowerShell 5.1 but needs to be re-written for 7
#region FUNCTIONS
function Initialize-EventLog
{
<#
.SYNOPSIS