Skip to content

Instantly share code, notes, and snippets.

View nyanhp's full-sized avatar

Jan-Hendrik Peters nyanhp

View GitHub Profile
if (-not (Test-IsAdministrator))
{
Write-Host -ForegroundColor Magenta 'Not an Admin :('
Start-Process -Verb runAs -FilePath (Get-Process -Id $pid).Path -ArgumentList "-File $PSScriptRoot" -WindowStyle Hidden
}
Write-Host -ForegroundColor Magenta 'Admin :)'
@nyanhp
nyanhp / TrayIconSample.ps1
Created March 31, 2022 12:50
Tray Icon with PowerShell
# Tray Icon requires Assemblies
Add-Type -AssemblyName System.Drawing
Add-Type -AssemblyName System.Windows.Forms
$tipTimeout = New-TimeSpan -Seconds 10
$trayIcon = [System.Windows.Forms.NotifyIcon]::new()
$trayIcon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon((Get-Process -Id $PID).Path)
$trayIcon.Text = "It Does things";
$trayIcon.Visible = $true;
$trayIcon.BalloonTipTitle = "Hi $env:USERNAME!";
@nyanhp
nyanhp / UpdateEverything.ps1
Last active July 2, 2020 08:57
Update local clone and default branch on GitHub
function Update-GitDefaultBranch
{
[CmdletBinding()]
param
(
# Base path where you store all your repos...
[Parameter(Mandatory)]
[string]
$Path,
@nyanhp
nyanhp / TheTask.ps1
Created June 25, 2020 11:35
Self-rescheduling task
$taskScript = {
# Do your stuff, start the service, ...
Start-Service -Name TheCrashingService
$triggers = @(
New-ScheduledTaskTrigger -Once -At (Get-Date).AddHours(12)
New-ScheduledTaskTrigger -AtLogOn -User 'someone'
)
$task = Get-ScheduledTask -TaskName YourScheduledTask
@nyanhp
nyanhp / WhyIsntItEasier.ps1
Last active July 11, 2022 12:48
Enable Power BI IP ranges on Azure SQL Firewall
function Enable-AllTheRules
{
[CmdletBinding()]
param
(
[Parameter(Mandatory)]
[string]
$ResourceGroupName,
[Parameter(Mandatory)]
@nyanhp
nyanhp / CookingALab.ps1
Last active May 11, 2021 15:52
Using AutomatedLab recipes
Install-Module AutomatedLab.Recipe -AllowClobber -Force
# Inline definition and execution
LabRecipe MySuperLab {
DeployRole = 'Domain', 'SQL'
VmPrefix = 'LB'
} | Invoke-LabRecipe
# Store a lab for later use
New-LabRecipe -Name MySuperLab -DeployRole DscPull,CI_CD
<#
Both files for my tests simply contained
{ bla = 'value }
and
{ bla = 'UserDefinedValue' }
#>
$d = @"
ResolutionPrecedence:
@nyanhp
nyanhp / New-IcsEvent.ps1
Created July 20, 2018 10:33
Use PowerShell to create new ICS files
function New-IcsEvent
{
[OutputType([System.IO.FileInfo[]])]
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Low')]
param
(
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[datetime[]]
$StartDate,
@nyanhp
nyanhp / WorldCupChecker.ps1
Created June 22, 2018 07:36
Checks for 2018 world cup results
# Install module for Toast Notifications
if (-not (Get-Module BurntToast -ListAvailable))
{
Install-Module BurntToast -Scope CurrentUser -Force
}
# Create path for state file
if (-not (Test-Path $env:APPDATA\Fuppes))
{
[void] (New-Item -ItemType Directory -Path $env:APPDATA\Fuppes)
@nyanhp
nyanhp / LabDriveStuff.ps1
Created April 11, 2018 09:37
Mount the AutomatedLab drive
# Install the module
Install-Module AutomatedLab.Ships
# Either Mount the drive yourself
Import-Module AutomatedLab.Ships
New-PSDrive -PSProvider SHiPS -Name Labs -Root "AutomatedLab.Ships#LabHost"
# Or simply import AutomatedLab to get one mapped for you
Import-Module AutomatedLab